Get queue message count

Im writing a integration test to my service bus , where i will publish a message then verify the message count , the only example i found to this seems outdated , any help would be appreciated

im connecting to the queue with the IQueueClient

 queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

           await queueClient.SendAsync(new Message(Encoding.UTF8.GetBytes("teste mensagem")));

im not finding any method to retrieve the message count, how can i achieve this? or is there another better way to do a integration test on the queue?

Upvotes: 0

Views: 828

Answers (1)

Sean Feldman
Sean Feldman

Reputation: 25994

To retrieve message counts you need to use ManagementClient. For queues, it has a GetQueueRuntimeInfoAsync() method that returns QueueRuntimeInfo object. This object has a property called MessageCount.

You might also want to look at another property it exposes, MessageCountDetails.

Upvotes: 1

Related Questions