How to get queue depth/length of azure queues when it exceeds int.MaxValue?

Sreekara Yachamaneni 40 Reputation points Microsoft Employee
2024-04-05T18:33:10.9366667+00:00

Currently we use QueueProperties.ApproximateMessagesCount to get the queue depth. Problem is the property is of type "int" and our queues can exceed int's max value. We rely on queue depth for important infrastructural/operational decisions. Is there a way to get exact queue depth (preferably long or ulong)?

Azure Queue Storage
Azure Queue Storage
An Azure service that provides messaging queues in the cloud.
97 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anand Prakash Yadav 5,845 Reputation points Microsoft Vendor
    2024-04-08T12:06:54.8333333+00:00

    Hello Sreekara Yachamaneni,

    Thank you for posting your query here!

    Adding on to the previous response, the ApproximateMessagesCount property of the QueueProperties class in Azure Storage Queues is indeed of type int. This means it can hold a maximum value of 2,147,483,647 (int.MaxValue), and it cannot be directly used to get the queue depth if it exceeds this value.

    https://learn.microsoft.com/en-us/dotnet/api/azure.storage.queues.models.queueproperties.approximatemessagescount?view=azure-dotnet

    Unfortunately, Azure Storage Queues does not provide a built-in way to get the exact queue depth as a long or ulong.

    Having more than 2 billion messages in a single queue is quite unusual and could indicate a need for a different architectural approach. For instance, partitioning the data across multiple queues.

    Please note that Azure queues are designed to handle a large number of messages but having billions of messages in a queue could potentially lead to other issues, such as increased latency or difficulties in managing and processing the messages efficiently.

    I hope this helps! Please let me know if the issue persists or if you have any other questions.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Michael Taylor 48,486 Reputation points
    2024-04-05T18:44:11.9233333+00:00

    I don't use this API but a quick look at the underlying API call involved indicates it comes from the x-ms-approximate-messages-count HTTP header. That value is limited to an int32 so if it is larger than that then you wouldn't be able to tell.

    If there is another way then I don't know what that would be. Of course I would question why you would have more than 2 billion messages in the queue at any one time anyway. I know Azure queues can handle millions of messages in the queue but billions seem like a stretch.

    1 person found this answer helpful.
    0 comments No comments