Last active
March 8, 2023 19:09
-
-
Save pc-m/e51c53e5a00394392c60ef98882d2d73 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| import kombu | |
| from kombu.mixins import ConsumerMixin | |
| from kombu import binding as Binding | |
| class C(ConsumerMixin): | |
| def __init__(self, connection): | |
| self.connection = connection | |
| def get_consumers(self, Consumer, channel): | |
| bindings = [] | |
| exchange = kombu.Exchange('wazo-headers', type='headers') | |
| bindings.append( | |
| kombu.binding( | |
| exchange=exchange, | |
| routing_key=None, | |
| ) | |
| ) | |
| return [ | |
| Consumer( | |
| kombu.Queue( | |
| exchange=exchange, | |
| routing_key=None, | |
| bindings=bindings, | |
| exclusive=True, | |
| ), | |
| callbacks=[self.on_message], | |
| ) | |
| ] | |
| def on_message(self, body, message): | |
| print(body, message.headers) | |
| message.ack() | |
| def main(): | |
| url_amqp = 'amqp://guest:guest@localhost:5672//' | |
| with kombu.Connection(url_amqp) as conn: | |
| try: | |
| C(conn).run() | |
| except KeyboardInterrupt: | |
| return | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment