5

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

Paul Fryer
  • 9,268
  • 14
  • 61
  • 93
  • Actually found the answer here: http://stackoverflow.com/questions/13957339/get-message-count-for-azure-topic-subscription Apparently you have to get the "SubscriptionDescription" from a "NamespaceManager", then you can get the message count. You can't get it from the SubscriptionClient directly however. – Paul Fryer Feb 26 '13 at 20:17
  • Ah okay, I didn't see your comment, my bad :) – Tom Kerkhove Aug 01 '14 at 12:02
  • 1
    FYI, the 'MESSAGE COUNT' includes messages dead letters and transferred. – Mikee Jan 07 '15 at 15:58

1 Answers1

2

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!

Tom Kerkhove
  • 2,151
  • 5
  • 26
  • 42
  • 2
    FYI, MessageCount includes any messages (Dead Letter and Transferred) in the Topic\Susbcrition. Use the MessageCountDetails property to split out the counts individually. NOTE also there seems to be a bug with these counts in that they report 0 unless some recent activity on the 'queue' has occurred. – Mikee Jan 07 '15 at 16:01
  • 1
    This answer is a bit misleading. `TopicDescription.MessageCountDetails` will report incorrectly as @Mikee noted - got stuck on this one. Solution was to use `SubscriptionDescription` the result of `GetSubscription(topicName, subscriptionName)` method. – Renatas M. Dec 10 '15 at 14:47