DAS_2024_1/pupkov_alexey_lab_4/Consumer_2.py

23 lines
807 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()