Skip to content

Instantly share code, notes, and snippets.

@MrZoidberg
Created March 28, 2021 19:37
Show Gist options
  • Save MrZoidberg/e2b4f21ee514477c4691ea932006ee16 to your computer and use it in GitHub Desktop.
Save MrZoidberg/e2b4f21ee514477c4691ea932006ee16 to your computer and use it in GitHub Desktop.
Rabbit consumer in Python
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='events', exchange_type='fanout')
result = channel.queue_declare(queue='create-order-failures', exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='events', queue=queue_name)
def callback(ch, method, properties, body):
print(" [x] %r" % body)
channel.basic_consume(
queue=queue_name, on_message_callback=callback, auto_ack=True)
channel.start_consuming()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment