Skip to content

Instantly share code, notes, and snippets.

@pc-m
Last active March 8, 2023 19:09
Show Gist options
  • Select an option

  • Save pc-m/e51c53e5a00394392c60ef98882d2d73 to your computer and use it in GitHub Desktop.

Select an option

Save pc-m/e51c53e5a00394392c60ef98882d2d73 to your computer and use it in GitHub Desktop.
#!/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