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

20 lines
703 B
Python

import pika
import json
import time
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='product_recommendation_queue')
channel.queue_bind(exchange='online_store_events', queue='product_recommendation_queue')
def callback(ch, method, properties, body):
message = json.loads(body)
print(f"Received message in product_recommendation_queue: {message}")
print(f"Обработка рекомендации: {message}")
channel.basic_consume(queue='product_recommendation_queue', on_message_callback=callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()