Search code examples
c#azure.net-coreazureservicebusazure-servicebus-queues

Get active message count with the new Azure.messaging.servicebus


Is there any option to retrieve the Active Message Count of a queue using the new Azure.messaging.servicebus package?

With the old Microsoft.azure.servicebus you could use ManagementClient that exposes GetQueueRuntimeInfoAsync(String, CancellationToken)

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

var messagesInQueueCount = runtimeInfo.MessageCountDetails.ActiveMessageCount;

Is there a way to achieve something similar? Thank you.


Solution

  • You can. The starting point would be a similar management client, ServiceBusManagementClient. It exposes methods to access entity runtime information such as GetQueueRuntimePropertiesAsync(), which returns QueueRuntimeProperties. The QueueRuntimeProperties object has all the info, including ActiveMessageCount.