Search code examples
c#asynchronousazureservicebusautoscaling

How to get the unprocessed message count from a Windows Service Bus Subscription?


I'm working on a system that needs to auto scale worker processes which pull messages from a service bus topic for processing.

To do this I need to know the number of unprocessed messages for a given subscription. How do I do that?

I had a look at the SubscriptionClient Class, but there doesn't appear to be a way to find the number of messages waiting to be processed.

enter image description here


Solution

  • You can use the NamespaceManager to get your QueueDescription or TopicDescription by using GetMessage(_name_) or GetTopic(_name_). These descriptions expose the value as MessageCount.

    Hope this helps!