user2574948
user2574948

Reputation: 267

Azure ServiceBus REST API total messages in a queue

I have been following the Azure Service Bus REST API documentation located at https://learn.microsoft.com/en-us/rest/api/servicebus/

I'm required to know the total number of messages in a queue before reading the first message. However, I cannot see a request/command to simply get the total/count number of messages in a given queue.

Is this not possible via the REST API and only available to SDK?

Thanks

Upvotes: 3

Views: 2924

Answers (2)

Gaurav Mantri
Gaurav Mantri

Reputation: 136136

You can certainly get this information through REST API. In fact, there are two different REST APIs using which you can get this information.

  1. Using Azure Resource Manager REST API - It is newer and recommended way to work with Service Bus Namespaces. The operation you would want to perform is Queues - Get. The response body will contain the details about the messages count. This API would require you to get an Azure AD access token which is then used for authorization.
  2. Using Old REST API - Though not recommended but you can use old Service Bus REST API to get the information. The operation you would to perform is Get Entity. This API would require you to use your Service Bus Namespace's shared access key for authorization.

Having said this, it is still recommended that you use the SDKs instead of consuming the REST API directly as SDKs are simply wrapper over REST APIs.

Upvotes: 1

Ricky Gummadi
Ricky Gummadi

Reputation: 5222

Yes you can you need to access it via the management API, more specifically this https://www.nuget.org/packages/Microsoft.Azure.Management.ServiceBus.Fluent/

Here is a great link explaining exactly how to use that package and get the counters you are after https://www.florinciubotariu.com/retrieving-number-of-messages-in-service-bus-in-net-core/

Upvotes: 0

Related Questions