Files
distributed-computing/tasks/ostrovskaya-sf/lab_4/lab_4_py/main_task/consumer_1.py
Софья Островская 7ea3ef3097 laba done
2023-12-15 19:09:53 +04:00

20 lines
648 B
Python

import pika
import time
def process_message(ch, method, properties, body):
print(f"Получено сообщение: {body}")
time.sleep(3)
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()