RabbitMQ – Getting Message Count in a Queue

Prerequisites :

having rabbitMQ and pika installed

sample.py

#!/usr/bin/env python
import pika

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

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s