23 lines
775 B
Python
23 lines
775 B
Python
import pika
|
|
import json
|
|
import time
|
|
|
|
credentials = pika.PlainCredentials('guest', 'guest')
|
|
connection = pika.BlockingConnection(
|
|
pika.ConnectionParameters(host='localhost', credentials=credentials))
|
|
channel = connection.channel()
|
|
|
|
channel.queue_declare(queue='order_queue_2')
|
|
|
|
channel.queue_bind(exchange='order_events', queue='order_queue_2')
|
|
|
|
def callback(ch, method, properties, body):
|
|
event = json.loads(body.decode('utf-8'))
|
|
print(f'Получено событие (очередь 2): {event}')
|
|
print(f'Обработка заказа {event["order_id"]} завершена.')
|
|
|
|
channel.basic_consume(queue='order_queue_2', on_message_callback=callback, auto_ack=True)
|
|
|
|
print('Ожидание сообщений (очередь 2)...')
|
|
channel.start_consuming()
|