Ubuntu Howto RabbitMQ Server on Maverick Meerkat 10.10 for python

To install RabbitMQ on Ubuntu 10.10 Maverick Meerkat do the following


sudo apt-get install python
sudo apt-get install python-pip git-core
sudo pip install -e git+http://github.com/tonyg/pika.git#egg=pika
sudo apt-get install rabbitmq-server


vi send.py and paste this in

#!/usr/bin/env python
import pika

connection = pika.AsyncoreConnection(pika.ConnectionParameters(
        host='localhost',
        credentials=pika.PlainCredentials('guest', 'guest')))
channel = connection.channel()

channel.queue_declare(queue='test')

channel.basic_publish(exchange='',
                      routing_key='test',
                      body='Hello World!')
print " [x] Sent 'Hello World!'"

vi receive.py and paste this in

#!/usr/bin/env python
import pika

connection = pika.AsyncoreConnection(pika.ConnectionParameters(
        host='127.0.0.1',
        credentials=pika.PlainCredentials('guest', 'guest')))
channel = connection.channel()

channel.queue_declare(queue='test')

print ' [*] Waiting for messages. To exit press CTRL+C'

def callback(ch, method, header, body):
    print " [x] Received %.20r" % (body,)

channel.basic_consume(callback,
                      queue='test',
                      no_ack=True)

pika.asyncore_loop()


Now run it! First send some messages....

python send.py

then try to receive them in another window. If you put both windows on the desktop you can send in one and receive in the other.

python receive.py

Here's an improved send2.py that will pass arbitrary command line string through the queue

just vi send2.py and paste this in

import pika
import sys

connection = pika.AsyncoreConnection(pika.ConnectionParameters(
        host='localhost',
        credentials=pika.PlainCredentials('guest', 'guest')))
channel = connection.channel()

channel.queue_declare(queue='test')
for arg in sys.argv:
   channel.basic_publish(exchange='', routing_key='test', body=arg)
   print " [x] Sent ", arg