123456789101112131415161718192021222324252627 |
- import pika
- import time
- connection = pika.BlockingConnection(pika.ConnectionParameters("localhost"))
- channel = connection.channel()
- channel.queue_declare(queue="task_queue", durable=True)
- print(" [*] Waiting for messages. To exit press CTRL+C")
- def callback(ch, method, properties, body):
-
- text = body.decode("utf-8")
- print(" [x] Received", text)
- time.sleep(text.count("."))
- print(" [x] Done")
- ch.basic_ack(delivery_tag=method.delivery_tag)
- channel.basic_qos(prefetch_count=1)
- channel.basic_consume(queue="task_queue", on_message_callback=callback)
- channel.start_consuming()
- connection.close()
|