distributed-computing/tasks/klementeva-ja/lab_4/python4Lab/Lab4MainTask/Consumer_2.py

19 lines
602 B
Python
Raw Permalink Normal View History

2023-12-16 11:48:57 +04:00
import pika
def process_message(ch, method, properties, body):
print(f"Получено сообщение: {body}")
print("Сообщение успешно обработано")
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='Agreements', queue=queue_name)
channel.basic_consume(queue=queue_name, on_message_callback=process_message, auto_ack=True)
print('Ожидание...')
channel.start_consuming()Ы