Created
February 16, 2018 09:47
-
-
Save celebdor/06cf4bf06637a72358b982832c366429 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
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