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.
CodePudding user response:
Use ServiceBusAdministrationClient()
var client = new ServiceBusAdministrationClient(_connectionString);
QueueRuntimeProperties queue = await client.GetQueueRuntimePropertiesAsync(queueName);
int count = (int)queue.ActiveMessageCount;
CodePudding user response:
The older way is to use the ManagementClient
var managementClient = new ManagementClient(connectionString);
var queueRuntimeInfo = await managementClient.GetQueueRuntimeInfoAsync(queueName);
Console.WriteLine(queueRuntimeInfo.MessageCount);
The more modern way is to use ServiceBusAdministrationClient
var client = new ServiceBusAdministrationClient(connectionString);
var runtimeProperties = await client.GetQueueRuntimePropertiesAsync(queueName);
Console.WriteLine(runtimeProperties .ActiveMessageCount);