DAS_2024_1/rogashova_ekaterina_lab_4/Consumer1.py
2024-11-15 11:50:03 +04:00

20 lines
644 B
Python

import pika
import json
import time
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='order_processing_queue')
channel.queue_bind(exchange='online_store_events', queue='order_processing_queue')
def callback(ch, method, properties, body):
message = json.loads(body.decode('utf-8'))
print(f"Received message in order_processing_queue: {message}")
time.sleep(2)
channel.basic_consume(queue='order_processing_queue', on_message_callback=callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()