Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do QueueClient.PeekBatch() and MessageReceiver.PeekBatch() not pull back the number of messages you specify

Both this:

queueClient.PeekBatch(Convert.ToInt32(60));

And this:

messageReceiver.PeekBatch(Convert.ToInt32(60));

Do not work "completely". They return a smaller amount, And instead I have to "pump" these methods in a loop up to the number of messages I know we have using :

var count = queue.MessageCountDetails.ActiveMessageCount;

What settings I am missing, why is Azure being so stingy and not allowing me to pull back, all 60 messages - I know that are there - at once?

like image 939
brumScouse Avatar asked Oct 30 '22 08:10

brumScouse


1 Answers

Well according to the azure samples the number you pass in is a upper bound, not an exact match. So you can only rely on it returning that number of messages or fewer.

https://github.com/Azure-Samples/azure-servicebus-messaging-samples/tree/master/MessageBrowse#using-peekbatch

"The count of 20 we pass into PeekBatchAsync for how many messages we'd like to obtain is an upper bound. The service may return any number of messages, up to 20 in this case, but will return at least one message if messages are available past the latest read sequence number"

Batching for azure service bus is normally only used as performance enhancement to avoid the overhead of returning messages one at a time. Internally it may have worked out that returning smaller but more batches is more performant. Batching using exact amounts is not something your program logic should rely upon, I only really use it to improve application performance since allows more throughput over individual peeks.

There also seems to limit in the amount of data returned in one batch which may be applicable to you.

"At most 256 kByte of cumulative message size will be returned in one batch call."

like image 193
UK-AL Avatar answered Nov 10 '22 17:11

UK-AL