RabbitMQ - Count the number of messages in a queue using the rabbitmqctl command
                
            
            
            
            
            
            
                           
                
            
            
            
                
    
    
    
            
                
                    by
                    Jeremy Canfield  |  
                    Updated: March 10 2022
                    
                          |  RabbitMQ articles
                    
                    
                    
                
            
            The rabbitmqctl command with the list_queues option can be used to list a virtual hosts queues and the number of messages in each queue.
rabbitmqctl list_queues
Which should produce something like this. By default, if the -p option is not used, the / virtual host will be used.
Listing queues for vhost / ...
name     messages
queue001 0
queue002 0
The -p option can be used to specify a virtual host, like this.
rabbitmqctl list_queues --vhost vhost001
Which should produce something like this.
Listing queues for vhost vhost001
name     messages
queue001 0
queue002 17
You can specify the items you wish to include in the output, like this.
rabbitmqctl list_queues name state messages messages_ready --vhost vhost001
Which should produce something like this.
Listing queues for vhost vhost001
name     state    messages messages_ready message_bytes_ready
queue001 running  0        0              0
queue002 running  17       17             157754
The --formatter json option can be used to return the output in JSON.
rabbitmqctl list_queues --formatter json
            
            Did you find this article helpful?
If so, consider buying me a coffee over at 