I am using service bus to communicate between web role and worker role, but it has been giving me some erratic results. I have deployed my cloud project to azure. So surprisingly when i run just the deployed project, the service bus works fine but when i also run the same project on my local emulator which is also using the service bus, service bus becomes faulty as in all the messages either to go to dead letter or are not received by the worker role. Is this a normal behavior for service bus? If not what could be the problem and how can i fix it?
This is irritating for me because now the service bus never works fine when i run my project on my local emulator.
This is how am sending and receiving messages, but i guess the problem might not be in it because it works fine when the service bus is being used just by the deployed project.
Worker Role:
public override void Run()
{
while (!IsStopped)
{
try
{
if (BroadcastReceived)
{
BroadcastReceived = false;
// Receive the message from Web Role to upload the broadcast to queue
BroadcastClient.BeginReceive(OnWebRoleMessageReceived, null);
}
if (SignalRMessageReceived)
{
SignalRMessageReceived = false;
// Receive the message from SignalR BroadcastHub
SignalRClient.BeginReceive(OnSignalRMessageReceived, null);
}
if (SignalRFirstTimeMessageReceived)
{
SignalRFirstTimeMessageReceived = false;
// Receive the message from SignalR BroadcastHub
SignalRFirstTimeClient.BeginReceive(OnSignalRFirstTimeMessageReceived, null);
}
}
}
public void OnWebRoleMessageReceived(IAsyncResult iar)
{
BrokeredMessage receivedBroadcastMessage = null;
receivedBroadcastMessage = BroadcastClient.EndReceive(iar);
if (receivedBroadcastMessage != null)
{
// Process the message
receivedBroadcastMessage.Complete();
}
BroadcastReceived = true;
}
Web Role:
var queueClient = CloudStorageHelper.GetServiceBusQueueClient(Queuenames.ApiToWorkerRole);
BrokeredMessage message = new BrokeredMessage(record);
queueClient.Send(message);
How am creating the service bus queues:
public static QueueClient GetServiceBusQueueClient(string queuename)
{
string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.QueueExists(queuename))
{
namespaceManager.CreateQueue(queuename);
}
QueueClient Client = QueueClient.CreateFromConnectionString(connectionString, queuename);
return Client;
}