This is a quick post on getting started using the txAMQP library with RabbitMQ on Ubuntu Jaunty.
Install RabbitMQ
1 | sudo apt-get install rabbitmq-server |
Note: Looks like the installer starts the rabbitmq-server automatically. I discovered this when I tried to start it from the terminal by running:
1 | sudo rabbitmq-server |
which was followed by a series of angry error messages. To confirm a node was already running I ran:
1 | sudo rabbitmqctl status |
In case a node is not already started you can run it attached or detached from the terminal:
1 | sudo rabbitmq-server |
1 | sudo rabbitmq-server -detached |
The server can be stopped with:
1 | sudo rabbitmqctl stop |
Install Twisted
1 | sudo apt-get install python-twisted |
Install txAMQP
The instructions below install txAQMP from trunk. There are Ubuntu packages available if you prefer, refer to the following for more details:
https://launchpad.net/~txamqpteam/+archive/ppa
a. Install Bazaar
1 | sudo apt-get install bzr |
b. Fetch txAQMP
1 2 | cd ~ bzr branch lp:txamqp txamqp |
c. Install txAMQP
1 2 | cd txamqp sudo python setup.py install |
Simple example
Esteve Fernandez, the author of txAMQP was kind enough to provide an example in the comments section of the Rabbits and warrens blog post which is a great read if you have not checked it out yet. You can review his comment here.
Let’s use his example to confirm our setup is working. First create a directory for the example and download the example files:
1 2 3 4 | mkdir ~/txamqp_example cd ~/txamqp_example wget http://fluidinfo.com/esteve/stuff/txamqp_consumer.py wget http://fluidinfo.com/esteve/stuff/txamqp_publisher.py |
Next, copy the amqp spec file into the example directory:
1 | cp ~/txamqp/src/specs/standard/amqp0-8.xml . |
To see this example work you will need to open two terminal windows. In the first window type the following:
1 2 | cd ~/txamqp_example python txamqp_consumer.py amqp0-8.xml |
In the second window type:
1 2 | cd ~/txamqp_example python txamqp_publisher.py amqp0-8.xml "message to send to consumer" |
You should see the message appear in the terminal window running the consumer.
Additional resources
RabbitMQ:
Twisted:
http://twistedmatrix.com/trac/
http://twistedmatrix.com/trac/wiki/TwistedAdvantage
txAMQP: