1

I want to read all messages from azure service bus (queue).

I have followed instruction from below link https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-php-how-to-use-queues

Currently it fetch one message..

I want to fetch all messages from service bus(queue).

Thanks in Advance..

2 Answers 2

2

I don't think it is possible to specify the number of messages you wish to read from the queue (at least with PHP SDK, it is certainly possible with .Net SDK). Essentially receiveQueueMessage is a wrapper over either Peek-Lock Message (Non-Destructive Read) or Receive and Delete Message (Destructive Read) (depending on the configuration) REST API methods and both of them return only a single message.

One way to solve this problem is to run your code in loop till the time you don't receive any message back from the queue. The issue that you could possibly run into with this is you may get back duplicate messages as once the lock acquired by peek-lock method is expired, the message will become visible again.

2
  • if I run code in loop .. then I need to delete message from queue, receiveQueueMessage function always return first message from queue....is their way to iterate without deleting message from queue.. Mar 30, 2018 at 9:44
  • That would depend on the lock duration setting on the queue. For example, if you’ve set this property to 1 Minute, then the first message will be repeated after 1 Minute. Mar 30, 2018 at 9:47
0

Reading all the messages in a Queue is possible with Peek operation concept of Service bus.

MessagingFactory messagingFactory = MessagingFactory.CreateFromConnectionString(<Your_Connection_String>);
var queueClient = messagingFactory.CreateQueueClient(<Your_Queue_Name>, ReceiveMode.PeekLock); // Receive mode is by default PeekLock and hence, optional.
BrokeredMessage message = null;
while(true)
{
  message = queueClient.Peek(); // You have read one message
  if (message == null) // Continue till you receive no message from the Queue
    break; 
}

This can also return expired or locked messages. Give a quick read about Message browsing if this suits your requirement of reading messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.