Some brief notes from playing around with RabbitMQ. This is also a handy opportunity to further test the GitHub to WordPress integration before I post some longer code!
Things are easy on the Mac since homebrew, though sometimes the magic goes wrong.
rabbitmq is available through homebrew, install it the usual way:
brew install rabbitmq
Part-way through installing the dependencies, I got the error:
Linking /usr/local/Cellar/erlang/R15B01… Warning: Could not link erlang. Unlinking…
Turns out (from running ‘brew doctor‘) that some of my /usr/local directories belonged to root, so I fixed it with:
chown -R myuser:admin /usr/local/share/man
brew link erlang
Then you need pip, in order to install pika.
(I think I got easy_install from installing the homebrew python; python seems infested with install tools; see stackoverflow’s why use pip over easy_install for information on old and busted versus new hotness).
So pip is there, next we install the actual python library for messaging:
sudo pip install pika==0.9.5
And then you’re good to go. Tutorial 1 code follows. Remember to start RabbitMQ before running either of these by doing:
#!/usr/bin/env python import pika connection = pika.BlockingConnection(pika.ConnectionParameters( 'localhost')) channel = connection.channel() channel.queue_declare(queue='hello') print ' [*] Waiting for messages. To exit press CTRL+C' def callback(ch, method, properties, body): print " [x] Received %r" % (body,) channel.basic_consume(callback, queue='hello', no_ack=True) channel.start_consuming()
#!/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()
And that’s it.