23 lines
807 B
Python
23 lines
807 B
Python
|
import pika
|
|||
|
|
|||
|
# Настройка соединения
|
|||
|
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
|
|||
|
channel = connection.channel()
|
|||
|
|
|||
|
# Создание очереди с фиксированным именем
|
|||
|
queue_name = 'orders_fast'
|
|||
|
channel.queue_declare(queue=queue_name)
|
|||
|
|
|||
|
# Binding очереди с exchange
|
|||
|
channel.queue_bind(exchange='orders_exchange', queue=queue_name)
|
|||
|
|
|||
|
# Callback для обработки сообщений
|
|||
|
def callback(ch, method, properties, body):
|
|||
|
print(f"[Consumer 2] Получено и обработано: {body.decode()}")
|
|||
|
ch.basic_ack(delivery_tag=method.delivery_tag)
|
|||
|
|
|||
|
channel.basic_consume(queue=queue_name, on_message_callback=callback)
|
|||
|
|
|||
|
print("[Consumer 2] Ожидание сообщений...")
|
|||
|
channel.start_consuming()
|