RabbitMQ – Getting Message Count in a Queue

Prerequisites :

having rabbitMQ and pika installed


#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
channel = connection.channel()
channel.basic_publish(exchange=”, routing_key=’hello’, body=’Hello World!’)
print(” [x] Sent ‘Hello World!'”)

This program can be run using the command  python sample.py

Now when we run this program the message “Hellow world ”  would be sent to the queue hello

The count of message in the queue hello can be retrieved by executing the following terminal command :

sudo rabbitmqctl list_queues | grep ‘hello’ 

This command would output something like this :

hello 1