I need to set an upper limit on how many messages can be in a queue. So obviously I need to know how many items are in a queue. How do you check the number of messages in a RabbitMQ queue from the c# client without hitting the management API or using QueueDeclarePassive?
Below is an example of the message count function on the IModel object. You do not need to use QueueDeclarePassive or make rest request to the management plugin. There is a function right there where it should be.
public uint GetMessageCount(string queueName)
{
using (IConnection connection = factory.CreateConnection())
using (IModel channel = connection.CreateModel())
{
return channel.MessageCount(queueName);
}
}
For documentation: https://rabbitmq.github.io/rabbitmq-dotnet-client/api/RabbitMQ.Client.IModel.html#RabbitMQ_Client_IModel_MessageCount_System_String_
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With