Files
2025-10-12 20:08:55 +04:00

20 lines
745 B
Python

import pika
queue_name = 'очередь 2'
exchange = 'logs'
def callback(ch, method, properties, body):
print(f" Consumer_2: сообщение получено {body.decode()}")
print(f" Consumer_2: сообщение обработано")
ch.basic_ack(delivery_tag=method.delivery_tag)
if __name__ == '__main__':
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
try:
channel.queue_declare(queue=queue_name)
channel.queue_bind(exchange=exchange, queue=queue_name)
channel.basic_consume(queue=queue_name, on_message_callback=callback)
channel.start_consuming()
except KeyboardInterrupt:
connection.close()