Created
July 24, 2019 13:16
-
-
Save ryanermita/07c07a2f2a1a800b1928ae371829af0c 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
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