4

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.

Florin Pilca
  • 154
  • 1
  • 1
  • 8
  • Are you talking about OR ?? I can't keep up with the newest-new with Microsoft and their ServiceBus library changes. – granadaCoder May 13 '22 at 20:22
  • 1
    The accepted answer here worked for me https://stackoverflow.com/questions/69706024/get-queue-message-count-using-microsoft-azure-management-servicebus – Lavamantis Jun 22 '22 at 16:22

1 Answers1

2

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.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80