Determining how many messages are on the Azure Service Bus Queue

后端 未结 9 831
难免孤独
难免孤独 2020-12-09 15:52

I know there is a way to determine the number of messages (or approximate number) in the Azure Queue (Store Account); however is there a way to query for the number of pendi

相关标签:
9条回答
  • 2020-12-09 16:32

    I ran into this same problem trying to get the count from the dead letter queue. It looks like the deadletterqueue doesn't allow you to get a count directly, you get it from the MessageCountDetails of the normal Queue.

    string connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.Connstr"].ToString();
    NamespaceManager nsmgr = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(connectionString);
    return nsmgr.GetQueue(QueueName).MessageCountDetails.DeadLetterMessageCount;
    
    0 讨论(0)
  • 2020-12-09 16:33

    Also..you can check the pending messages on Azure Management Portal...on the dashboard for service bus queue...under quick glance...you can see the queue length...this is the number of current/pending messages in length at the time of dashboard page load.

    0 讨论(0)
  • 2020-12-09 16:40

    Based off what Joseph had as an answer I came up with, but for Topics and Subscriptions.

    public async Task<long> GetCounterMessages()
            {
                var client = new ManagementClient(ServiceBusConnectionString);    
                var subs = await client.GetSubscriptionRuntimeInfoAsync(TopicName, SubscriptionName);
                var countForThisSubscription = subs.MessageCount;  //// (Comes back as a Long.)               
                return countForThisSubscription;
            }
    
    0 讨论(0)
提交回复
热议问题