0

I try to get 32 messages per request from Azure Queue.

queue.ApproximateMessageCount;

This code gives me the result of 1509. Telling me the connection is OK and it has records. Also I check in queue it really has 1509 records. But when I try to retrieve records I don't get any record. I do the following:

var messages = await queue.GetMessagesAsync(configuration.MessageBatchSize);
if (!messages.Any()) {
    return;
}

It always goes in the if and returns. What is going on here and what am I missing?

M Reza
  • 18,350
  • 14
  • 66
  • 71
apero
  • 1,074
  • 2
  • 23
  • 38
  • 1
    Could it be possible that all the messages in your queue are dequeued? – Gaurav Mantri Apr 24 '18 at 11:17
  • 1
    if messages are dequeued, than its gone right? Count shouldn't show a count of 1509 right? – apero Apr 24 '18 at 11:19
  • 2
    Not true. Dequeued messages are still in the queue so their count is included in approximate messages count. Only when a message is deleted, then its gone. – Gaurav Mantri Apr 24 '18 at 11:28
  • for receiving messages in batch mode the queue have to be configured for that (EnableBatchedOperations set to true) – volia17 Apr 25 '18 at 09:48

2 Answers2

0

Do do that, receiving messages in batch mode, i use this kind of code :

var messages = await queueClient?.ReceiveBatchAsync(Max_Messages);
foreach (var message in messages)
{
    await dispatcher.Dispatch(message); // do something with each message
}

But, for receiving messages with ReceiveBatchAsync, the queue have to be configured with the EnableBatchedOperations flag to true.

volia17
  • 938
  • 15
  • 29
0

ApproximateMessageCount property represents the total number of messages available in queue at that particular moment. It does not represent that all messages (max #32 messages in a pull) are ready to be dequeued. You can use this property to infer that how many messages are in queue.

queue.ApproximateMessageCount;

If you could not retrieve the message by, GetMessagesAsync(numberOfMessages), then it says that all messages are not available or invisible for current QueueClient.

var cloudQueueMessages = await cloudQueue.GetMessagesAsync(numberOfMessages);

You could try polling the queue after sometime to see if messages came back to surface.

Note that, be advised of setting adequate visibility timeout for any message being dequeued to avoid indefinite starvation :)

Ashokan Sivapragasam
  • 2,033
  • 2
  • 18
  • 39