Determining how many messages are on the Azure Service Bus Queue

后端 未结 9 830
难免孤独
难免孤独 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:19

    I've spent good 2 hours digging through docs to get that and for people using .net core and Microsoft.Azure.ServiceBus nuget package, code looks like that:

    var managementClient = new ManagementClient("queue connection string"));
    var runtimeInfo = await managementClient.GetQueueRuntimeInfoAsync("queueName");
    
    var messagesInQueueCount = runtimeInfo.MessageCountDetails.ActiveMessageCount;
    

    Aparently you get the information about all Counts(including deadletter, active, etc.) from QueueRuntimeInfo object instead of old QueueDescription object.

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

    have you looked at the Queue Description API? There's a property called MessageCount.

    Here's the .NET SDK reference documentation page as well.

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

    As per the recommendation by Microsoft, it is recommended to use Microsoft.Azure.ServiceBus in which you can easily fetch the message count by

    var managementClient = new ManagementClient("connection string for queue");
    var queue = await managementClient.GetQueueRuntimeInfoAsync("queue name");
    var messages = queue.MessageCount;
    
    0 讨论(0)
  • 2020-12-09 16:29

    It is called MessagesCountDetails.ActiveMessageCount. It returns the number of the Active Messages in the Queue. You probably have some Dead letter messages:

    var msg = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(Settings.Default.ConnectionString);
    numofmessages.Text = msg.GetQueue(QueueName).MessageCountDetails.ActiveMessageCount.ToString();
    
    0 讨论(0)
  • 2020-12-09 16:29

    Here's a PowerShell example to continually eyeball the queue length as used in Azure Portal Cloud Shell

    cd "Azure:\<MySubscription>\"
    while (1) {(Get-AzureRmServiceBusQueue -ResourceGroup <myRG> -NamespaceName <myNS> -QueueName <myQueueName>).CountDetails | Select -expand ActiveMessageCount}
    
    0 讨论(0)
  • 2020-12-09 16:32
    var nsmgr = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(connectionString);
    long count = nsmgr.GetQueue(queueName).MessageCount;
    
    0 讨论(0)
提交回复
热议问题