Created
July 22, 2014 02:50
-
-
Save darth30joker/b5a3015c910a21470f52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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