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

How to get queue size of the Azure Service Bus using .NET API in C#


I am working on a .NET Core project. I am trying to connect to the service bus queue using a connection string. I am able access the service bus with QueueClient using the API function 'new QueueClient(< connection string >, < queue name >). However Queue client does not have any functions to get the size / message count.

I have tried the NamespaceaManager.CreateFromConnectionString (< connection string >) function, but looks like its been deprecated in .NET Core (and it keeps throwing dependency errors).

I tried the Microsoft.Azure.Management.Fluent package but could not get it to work either.

Are any of these the right way to do it, and is there any other way to make this work?


Solution

  • NamespaceaManager is not available with the new Azure Service Bus client library. It's planned to add support for some of the functionality NamespaceManager used to provide, but not queue size. For that, you will need to use Azure Monitor service that can provide message counts and entity size (additional information and a sample). Also, entity metrics via REST API were deprecated and Azure Monitor should be used instead.