Getting Azure Service Bus Queue ActiveMessageCount with .Net Core and C#

Eduard Los
1 min readMar 2, 2020

Couple of days ago I needed to get ActiveMessageCount property from Azure Service Bus Queue, which didn’t look like complicated task. In fact, it is not a complicated problem, but with all the functionality migrations and refactorings on Microsoft side, documentation became a bit messy and I have spent good 2 hours digging for the solution.

It’s 3 lines of code once you find where to look:

var managementClient = new ManagementClient("queue connection string"));var runtimeInfo = await managementClient.GetQueueRuntimeInfoAsync("queueName");

var messagesInQueueCount = runtimeInfo.MessageCountDetails.ActiveMessageCount;

For this code to work, you need Microsoft.Azure.ServiceBus nuget package or any one that has this package in dependencies.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Eduard Los
Eduard Los

Written by Eduard Los

Software engineer, architect, tech enthusiast.

Responses (1)

Write a response

Exactly what I need. Thanks!

--

Recommended from Medium

Lists

See more recommendations