Skip to content

Instantly share code, notes, and snippets.

@chipchilders
Created July 17, 2013 18:18
Show Gist options
  • Save chipchilders/6023038 to your computer and use it in GitHub Desktop.
Save chipchilders/6023038 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import pika
# Creates a connection to the RabbitMQ broker running on localhost
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
# Gets a channel to use for communicating with the broker
channel = connection.channel()
# Declares a new queue within the broker
result = channel.queue_declare(exclusive=True)
# Finds the auto-generated queue name to use when binding the queue
# to the exchange
queue_name = result.method.queue
print 'Created Queue: ' + queue_name
# Binds the queue to the cloudstack-events
# exchange, with a wildcard routing key.
# The wildcard key will cause all messages
# sent to the exchange to be published to
# your new queue.
channel.queue_bind(exchange='cloudstack-events',
queue=queue_name,
routing_key = '*.*.*.*.*')
print ' [*] Waiting for logs. To exit press CTRL+C'
# A simple callback method that will print
# the routing_key and message body for any
# message that it receives.
def callback(ch, method, properties, body):
print " [x] %r:%r" % (method.routing_key, body,)
# Tell the channel to use the callback
channel.basic_consume(callback,
queue=queue_name,
no_ack=True)
# And start consuming events!
channel.start_consuming()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment