Skip to content

Instantly share code, notes, and snippets.

@darth30joker
Created July 22, 2014 02:50
Show Gist options
  • Save darth30joker/b5a3015c910a21470f52 to your computer and use it in GitHub Desktop.
Save darth30joker/b5a3015c910a21470f52 to your computer and use it in GitHub Desktop.
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
'localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='messages', type='direct')
routings = ['info', 'warning', 'error']
# declare a queue to receive messages from exchange
# and bind queue to a routing_key
# this means, this queue can only receive message with this label
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
for routing in routings:
channel.queue_bind(exchange='messages',
queue=queue_name,
routing_key=routing)
def callback(ch, method, properties, body):
print " [x] Received %r" % (body,)
channel.basic_consume(callback, queue=queue_name, no_ack=True)
channel.start_consuming()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment