0

I have been using azure service bus to send messages to and fro between web role and worker role and i really thought that it was a really good solution but lately i have found that service bus is very erratic, sometimes it works and sometimes the messages go into dead letter for no reason at all. I dont know if its a problem in my code, but it looks to me that it is just erratic because sometimes it works and sometimes it doesnt. So i wanted to know if there are any alternative solution to service bus or i would be very happy to know any mistakes am doing in service bus implementation which is resulting in my above problem. Below is my code

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;
 }

In the above code I am showing the method of only one service bus client. In my worker role there is use of 3 service bus clients, i.e am asynchronously sending and receiving messages from different queues. Its really weird how some messages work and some go to dead letter without any reason, sometimes its alternate so i thought there must be a problem in my code but i cant find any. Please let me know if anyone has nay idea what the problem is

knightpfhor
  • 9,299
  • 3
  • 29
  • 42
Bitsian
  • 2,238
  • 5
  • 37
  • 72

2 Answers2

0

Have you considered NServiceBus? I'm not sure if there are alot of examples about integrating SignalR and NServiceBus, but googling around should get you started

http://ben.onfabrik.com/posts/push-notifications-with-nservicebus-and-signalr

Igorek
  • 15,716
  • 3
  • 54
  • 92
  • But with azure storage queues, i would have to poll the queues repeatedly to check if there are any new messages on the queue! I dont want to do that as it will increase my cost by a huge margin.....thats why i had preferred service bus in the first place but unfortunately service bus doesnt seem to be reliable enough! Any other ideas? – Bitsian Mar 04 '13 at 19:13
  • Thanks, will check it out! Also If you dont mind can u look at my service bus code and let me know if you find any mistakes that might be causing the problem? – Bitsian Mar 05 '13 at 05:16
0

There are a few reasons why message go into DeadLetter Queue without the explicit call to message.DeadLetter(). Check the following: 1) TimeToLive on the Queue and the message, if this time expires then messages are deadlettered and not delivered. By default this is infinite. 2) Delivery count determines how many times a message is received before being deadlettered. Above I do not see any exception handling so say you were getting an error during message processing and complete was not called on the message, the delivery count would increase. On the Queue you have the option to set how many times the message should be delivered before it is dead-lettered.

Abhishek Lal
  • 3,233
  • 1
  • 17
  • 16
  • MaxDeliveryCount is by default set to 10, so unfortunately thats not the reason. I have a feeling it is something to do with how am asynchronously handling 3 service bus clients at the same time. Any inputs on that? – Bitsian Mar 06 '13 at 06:18