Retrieve A Batch Of Messages - Understanding Queue Storage - Part Four

In the previous exercise, we have seen how to retrieve the next message in a queue. Here in this article, we will see how to get a batch of messages. In Azure Queue Storage you can get a batch of messages (up to 32). The following code example uses the GetMessages method to get 6 messages in one call. Then it processes each message using a foreach loop and deques the same.

Step 1

Before starting this demo, I have already added five more messages to our queue. You can do it either by using the code or directly in the portal by selecting the queue and using the add message option

Azure 

Azure 

Step 2

Replace the cod2 to retrieve one message with the following code.
  1. foreach (CloudQueueMessage message in queue.GetMessages(6))  
  2. {  
  3.    Console.WriteLine(message.AsString);  
  4.    queue.DeleteMessage(message);  
  5. }  
  6. Console.ReadLine();  
Azure

Step 3

Run your application and you can see a batch of messages up to six in count as we specified in the console window and the same has been dequeued after processing. (Here it's showing as output in the console window)

Azure
 
Azure