0
votes

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

I have followed instruction from below link https://docs.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

2 Answers

2
votes

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.

0
votes

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.