Skip to content

Instantly share code, notes, and snippets.

@celebdor
Created February 16, 2018 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celebdor/06cf4bf06637a72358b982832c366429 to your computer and use it in GitHub Desktop.
Save celebdor/06cf4bf06637a72358b982832c366429 to your computer and use it in GitHub Desktop.
from kombu import Connection, Exchange, Queue
from kombu.mixins import ConsumerMixin
rabbit_url = "amqp://stackrabbit:pass@10.16.144.168:5672/"
class Worker(ConsumerMixin):
def __init__(self, connection, queues):
self.connection = connection
self.queues = queues
def get_consumers(self, Consumer, channel):
return [Consumer(queues=self.queues,
callbacks=[self.on_message])]
def on_message(self, body, message):
print('Got message: {0}'.format(body))
message.ack()
exchange = Exchange('neutron', type='topic', durable=False, auto_delete=False)
queues = [Queue('notifications.info', exchange, routing_key='notifications.info', durable=False, auto_delete=False, exclusive=False)]
with Connection(rabbit_url, heartbeat=4) as conn:
worker = Worker(conn, queues)
worker.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment