简体   繁体   中英

Get queue message count using Microsoft.Azure.Management.ServiceBus

I need an example on how to make CRUD operations on service bus queues.

I actually need an instance of Microsoft.Azure.Management.ServiceBus.SBQueue class, so I can count the messages in that queue.

Use the ManagementClient to call GetQueuesRuntimeInfoAsync , which gives you the QueueRuntimeInfo which has a member MessageCount

var managementClient = new ManagementClient(connectionString);
var queueRuntimeInfo = await managementClient.GetQueueRuntimeInfoAsync(queueName);
Console.WriteLine(queueRuntimeInfo.MessageCount);

Use ServiceBusAdministrationClient()

var client = new ServiceBusAdministrationClient(_connectionString);
QueueRuntimeProperties queue = await client.GetQueueRuntimePropertiesAsync(queueName);
int count = (int)queue.ActiveMessageCount;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM