For logging purposes, I want to get the message count of an Azure Service Bus subscription, given a subscription client. The only examples I found use the NamespaceManager
, but that seems a bit redundant to me since I already have a SubscriptionClient
. Is there a way to go directly from the client to the SubscriptionDescription
?
Fwiw, I tried using the detour via the name space manager, but I get a it throws a 401 Unauthorized error:
int GetMessageCount(SubscriptionClient client) {
NameSpaceManager nsm = new NamespaceManager(client.MessagingFactory.NamespaceEndpoints.First());
SubscriptionDescription desc = nsm.GetSubscription(client.TopicPath, client.Name); // <-- throws error
long numMsg = desc.MessageCount;
return numMsg;
}