Skip to content

Instantly share code, notes, and snippets.

@ryanermita
Created July 24, 2019 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanermita/07c07a2f2a1a800b1928ae371829af0c to your computer and use it in GitHub Desktop.
Save ryanermita/07c07a2f2a1a800b1928ae371829af0c to your computer and use it in GitHub Desktop.
import pika
import time
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='direct_exchange', exchange_type='direct')
channel.queue_declare(queue='direct_queue', durable=True)
channel.queue_bind(exchange='direct_exchange', queue="direct_queue", routing_key="direct.routing.key")
def callback(ch, method, properties, body):
print("Received %r" % body)
time.sleep(body.count(b'.'))
print("Done")
ch.basic_ack(delivery_tag=method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback, queue='direct_queue')
print('Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment