How to determine the number of messages in an Azure Services Bus Queue

0 votes

Can anyone let me know if there is a way to determine the number of messages (or approximate number) in the Azure Queue (Store Account); however is there a way to query for the number of pending messages on an Azure Service Bus queue?

Jun 12, 2018 in Azure by cloudie_crank
• 1,610 points
4,643 views

1 answer to this question.

0 votes

You will get error when you try to get the count from the dead letter queue. It looks like the deadletterqueue doesn't allow you to get a count directly, you get it from the MessageCountDetails of the normal Queue:

string connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.Connstr"].ToString();
NamespaceManager nsmgr = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(connectionString);
return nsmgr.GetQueue(QueueName).MessageCountDetails.DeadLetterMessageCount;

And for your second question, the required function is called MessagesCountDetails.ActiveMessageCount. It returns the number of the Active Messages in the Queue. You probably have some Dead letter messages:

var msg = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(Settings.Default.ConnectionString);
numofmessages.Text = msg.GetQueue(QueueName).MessageCountDetails.ActiveMessageCount.ToString();


Hope it helps!

If you need to know more about Azure, then you should join Azure cloud certification course today.

Thank you!!

answered Jun 12, 2018 by null_void
• 3,220 points

Related Questions In Azure

0 votes
1 answer

How to get the list of names of Azure blob files in a container?

We can get some additional info like Size, ...READ MORE

answered Jun 27, 2018 in Azure by club_seesharp
• 3,450 points
21,899 views
0 votes
1 answer

How to pass object messages in Azure Queue Storage?

I already have a base class, so ...READ MORE

answered Mar 26, 2019 in Azure by Prerna
• 1,960 points
3,545 views
0 votes
1 answer

How to calculate the used database space in SQL Azure?

I don't think its possible to find ...READ MORE

answered Mar 5, 2019 in Azure by Archana
• 5,640 points
1,270 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

How to list the subscriptions of a Azure account?

Hi@akhtar, You can get all the subscriptions for ...READ MORE

answered Nov 10, 2020 in Azure by MD
• 95,460 points

edited Jul 4, 2023 by Khan Sarfaraz 1,213 views
0 votes
1 answer

How to set the subcription in the Azure account?

Hi@akhtar, You can set your required subscription to ...READ MORE

answered Nov 10, 2020 in Azure by MD
• 95,460 points
638 views
+1 vote
2 answers

How do I establish an connection to Azure IoT Hub? Say a connection like MQTT/AMQP using Python.

Azure IoT Hub comes with 3 SDK's: Service SDK Device ...READ MORE

answered Apr 13, 2018 in Azure by null_void
• 3,220 points
2,243 views
0 votes
1 answer

How can we rewrite an URL in Azure Webapp?

You need to create a web.config file ...READ MORE

answered Jun 14, 2018 in Azure by null_void
• 3,220 points
8,753 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP