Determining how many messages are on the Azure Service Bus Queue Determining how many messages are on the Azure Service Bus Queue azure azure

Determining how many messages are on the Azure Service Bus Queue


var nsmgr = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(connectionString);long count = nsmgr.GetQueue(queueName).MessageCount;


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();