Skip to content

Instantly share code, notes, and snippets.

@wh13371
Created June 20, 2020 09:30
Show Gist options
  • Save wh13371/9347a5c9252cd419ba44ca45de5c842f to your computer and use it in GitHub Desktop.
Save wh13371/9347a5c9252cd419ba44ca45de5c842f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import pika
credentials = pika.PlainCredentials('fizz', 'fizz')
parameters = pika.ConnectionParameters(host='?.?.?.?',
port=5672, credentials=credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.exchange_declare(exchange='logs', exchange_type='fanout')
result = channel.queue_declare(queue='fizz', exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='logs', queue=queue_name)
print(queue_name)
print(' [*] Waiting for logs. To exit press CTRL+C')
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