Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check RabbitMQ queue size from client

People also ask

How do I check my RabbitMQ queue size?

The API documentation is installed along with the RabbitMQ management console and should be available on that server at http://MY_RABBITMQ_SERVER:15672/api . Show activity on this post. I was able to get the size/depth of queue from python program.

What is the default queue size in RabbitMQ?

Define Max Queue Length Using a Policy When the 1MiB limit is reached, the oldest messages are discarded from the head of the queue. The my-pol policy ensures that the two-messages queue contains no more than 2 messages and all additional publishes are sent basic.

How do I know if my RabbitMQ queue is empty?

In php-amqlib: $channel->basic_get(QUEUE_NAME, true); // the second arg is no_ack . The second argument marks that no acknowledgment is expected for that message. That is, you don't have to "flag" the message as read for RabbitMQ to confidently dequeue it.

How many messages can a RabbitMQ queue hold?

Queues are single-threaded in RabbitMQ, and one queue can handle up to about 50 thousand messages.


You can actually retrieve this via the client.

When you perform a queue_declare operation, RabbitMQ returns a tuple with three values: (<queue name>, <message count>, <consumer count>). The passive argument to queue_declare allows you to check whether a queue exists without modifying the server state, so you can use queue_declare with the passive option to check the queue length.

Not sure about .NET, but in Python, it looks something like this:

name, jobs, consumers = chan.queue_declare(queue=queuename, passive=True)

I am 2 years too late but I was searching for it myself and found that rabbitmq gives u simple script to communicate to erlang nodes..its in sbin folder where the starting script for RabbitMQ is located..so you can basically say

./rabbitmqctl list_queues

this will display the queues along with the count of messages pending to those queues similarly you can also say

./rabbitmqctl list_channels
./rabbitmqctl list_connections

etc. For more info you can visit here


If you want to do this in .NET, check which version of the client library you are using.

I'm using the 2.2.0 version and I had to use BasicGet(queue, noAck).
In this version of the library, QueueDeclare() only returns a string containing the queue name.

BasicGetResult result = channel.BasicGet("QueueName", false);
uint count = result != null ? result.MessageCount : 0;

I know from the 2.6.1 version, QueueDeclare() returns an object of type QueueDeclareOk.

QueueDeclareOk result = channel.QueueDeclare();
uint count = result.MessageCount;

Alternatively, you can call from the command line:

<InstallPathToRabbitMq>\sbin\rabbitmqctl.bat list_queues

And you see the following output:

Listing queues...
QueueName 1
...done.


I'm using version 3.3.1 of the .NET client library.

I use the following, which is very similar to Ralph Willgoss's second suggestion, but you can supply the queue name as an argument.

QueueDeclareOk result = channel.QueueDeclarePassive(queueName);
uint count = result != null ? result.MessageCount : 0;

my little snippet based on Myydrralls' answer. I think if he had code in his answer I might have noticed it much quicker.

public uint GetMessageCount(string queueName)
{
    using (IConnection connection = factory.CreateConnection())
    using (IModel channel = connection.CreateModel())
    {
        return channel.MessageCount(queueName);
    }
}