Home > Back-end >  Get active message count with the new Azure.messaging.servicebus
Get active message count with the new Azure.messaging.servicebus

Time:02-10

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.

CodePudding user response:

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.

  • Related