Java: Receive answer from Windows Azure Service Bus Queue

Category: azure connectivity

Question

mwpsp on Wed, 31 Jul 2013 12:21:21


Hi,

I'm trying to implement Request Response Queue using Windows Azure Service Bus Queue. I created two queues: Request and Response.

My client side send message to Request queue, then my server side take this message from Request queue, do something and put response into Response Queue. The client side check Response queue if there are any messages. When I run only one client it's working fine.

When I run more then one client, after some time clients side don't pull off any message from Response queue. This queue for sure isn't empty, because client side check how many messages are there.

For receiving message I use:

ReceiveMessageOptions options = ReceiveMessageOptions.DEFAULT;

options.setReceiveMode(ReceiveMode.PEEK_LOCK);

options.setTimeout(20);

ReceiveQueueMessageResult resultQueueMessage = service.receiveQueueMessage(responseQueueName);

BrokeredMessage receivedMessage = resultQueueMessage.getValue();

Any help would be appreciated,

Asia

Replies

MingXu-MSFT on Thu, 01 Aug 2013 07:06:05


Hi,

  >> When I run more then one client, after some time clients side don't pull off any message from Response queue.

In order for us to better understand the issue, please let us know the detailed information of your scenario. Based on your description, it seems you want to use a single queue to store all clients' responses. I am not sure how you distinguish responses that belong to different clients. From my experience, this may not work as you expect since a message in a queue can only be read once (unless the peek lock timeout expires).

  >> This queue for sure isn't empty, because client side check how many messages are there.

Imagine you have two clients A and B. Your service sends 10 messages to the response queue, the first 5 messages are for A, and the latter 5 are for B. However, B may check the queue before A, and thus B got the first message. B thinks this message is not for him, and thus ignores it. But the message is already read, and is no longer available to A. Thus A can only read from the second message. This may be the cause of this issue.
 
If you want each client to get its own response, it is needed to create a queue for each client. If you want to broadcast messages to all clients, then I'd like to suggest you to use topics instead of queues. Queue in general is for a single client, while topic is for multiple clients. You can refer to http://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-topics/ and http://msdn.microsoft.com/en-us/library/windowsazure/hh367516.aspx for more information.

Best Regards,

Ming Xu

mwpsp on Thu, 01 Aug 2013 07:22:46


Hi,

Thank you for the reply.

When I send message to request queue, I set it properties: replyToSessionId, SessionId and MessageID. My response message has exaclty the same value of these properties. Thanks to that I recognize which response message belongs to which client. I based on project: http://code.msdn.microsoft.com/windowsazure/Brokered-Messaging-Request-0ce8fcaf

In this project there is only one response queue. I wanted to write the same in Java but without success.

Regards,

Asia

MingXu-MSFT on Thu, 01 Aug 2013 16:46:26


Hi,

I am not very familiar with Java, for now I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

Best Regards,

Ming Xu

Mike Wong on Thu, 01 Aug 2013 20:54:47


Hello Asia,

could you capture a trace using Fiddler (fiddler2.com) when you call receiveQueueMessage?  I am wondering what http status code you are getting back on the machine when it is not pulling any messages from the service bus queue.

Also are you able to retrieve messages from the queue using Service Bus Explorer 2.0 (http://code.msdn.microsoft.com/windowsazure/Service-Bus-Explorer-f2abca5a)  What do the metrics look like for the queue when you can't receive?

Much appreciated,

Mike Wong

Microsoft Developer Support