Reputation: 267
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
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.
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.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
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