Reputation: 171
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.
Upvotes: 1
Views: 2193
Reputation: 81583
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);
Upvotes: 5
Reputation: 171
Use ServiceBusAdministrationClient()
var client = new ServiceBusAdministrationClient(_connectionString);
QueueRuntimeProperties queue = await client.GetQueueRuntimePropertiesAsync(queueName);
int count = (int)queue.ActiveMessageCount;
Upvotes: 2