Determining how many messages are on the Azure Ser

2019-01-24 00:17发布

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 pending messages on an Azure Service Bus queue?

6条回答
Animai°情兽
2楼-- · 2019-01-24 00:57
var nsmgr = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(connectionString);
long count = nsmgr.GetQueue(queueName).MessageCount;
查看更多
Root(大扎)
3楼-- · 2019-01-24 01:01

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.

查看更多
可以哭但决不认输i
4楼-- · 2019-01-24 01:02

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;
查看更多
够拽才男人
5楼-- · 2019-01-24 01:08

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();
查看更多
成全新的幸福
6楼-- · 2019-01-24 01:09

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}
查看更多
兄弟一词,经得起流年.
7楼-- · 2019-01-24 01:13

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

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

查看更多
登录 后发表回答