Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Storage Queues - Counting visible messages

I have a distributed application which share loads with Azure Storage queues. In order to verify that everything is working good, I'm wrote a small application that run every 10 minutes and check how much items is in queue. If the number is above the threshold, send me a notification message.

This is how I'm running over all queues:

Dictionary<string, int> dic = new Dictionary<string, int>();
foreach (CloudQueue queue in QueuesToMonitor)
{
    queue.FetchAttributes();
    dic.Add(queue.Name, queue.ApproximateMessageCount.HasValue ? queue.ApproximateMessageCount.Value : -1);
}

This code is working fine but it also counting messages which hidden. I'm want to exclude those messages from counting (because those task are not ready to be executed).

For exeample, I'm checked one of my queues and got an answer that 579 items is in queue. But, actully is empty of visible items. I'm verify this with Azure Storage Explorer: 0 of 579

How can I count only the visible items in queue?

like image 222
No1Lives4Ever Avatar asked Nov 08 '22 00:11

No1Lives4Ever


1 Answers

Short answer to your question is that you can't get a count of only visible messages in a queue.

Approximate messages count will give you an approximate count of total messages in a queue and will include both visible and invisible messages.

One thing you could possibly do is PEEK at messages and it will return you a list of visible messages. However it will only return you a maximum of top 32 messages from the queue. So you logic to send notification message would work if the threshold is less than 32.

like image 115
Gaurav Mantri Avatar answered Nov 15 '22 05:11

Gaurav Mantri