Receiving multiple messages from a queue without a loop

I use Azure Service Bus to manage messages using webrole and workerrole.

I need to know how I can get several messages from the queue at once without using a loop.

+4
source share
3 answers

There is no way in Service Bus queues to receive more than one message at a time, but you can configure a prefetch in which messages will be cached (which will increase performance). Read more about prefetch here .

If you really need mass-read messages, consider what @AvkashChauhan said: Windows Azure Storage Queues support up to 32 messages that need to be read right away in a single transaction. You need to individually delete each message in the queue; there is no batch removal.

+4
source

You can use the ReceiveBatch method for Microsoft.ServiceBus.Messaging:

private MessageReceiver messageReceiver; var brokeredMessagesList = messageReceiver.ReceiveBatch(100); 

You can put the lock in the queue until the processing of the received batch is completed, and after processing is complete, you can call CompleteBatch to release the lock in the queue:

  List<Guid> messageLockTokenList = new List<System.Guid>(); foreach(BrokeredMessage message in brokeredMessagesList) { messageLockTokenList.Add(message.LockToken); } messageReceiver.CompleteBatch(messageLockTokenList) 
+4
source

When you receive messages from a queue, combine several messages in a single storage transaction. The GetMessages method in the queue API allows you to disable the specified number of messages in one transaction

When receiving messages using the GetMessages method, the maximum packet size supported by the Queue Service APIs in a single decompression operation is limited to 32. Exceeding this limit will result in a runtime exception.

Visit here for more details: http://windowsazurecat.com/2010/12/best-practices-for-maximizing-scalability-and-cost-effectiveness-of-queue-based-messaging-solutions-on-windows-azure /

+2
source

Source: https://habr.com/ru/post/1416675/


All Articles