29 lines
850 B
Python
29 lines
850 B
Python
|
import pika
|
||
|
|
||
|
|
||
|
def callback(ch, method, properties, body):
|
||
|
print(f'Consumer 2 получил сообщение: {body.decode()}')
|
||
|
|
||
|
# Обработка "нон-стопом"
|
||
|
print('Consumer 2 закончил обработку')
|
||
|
|
||
|
|
||
|
def consume_events_2():
|
||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
||
|
channel = connection.channel()
|
||
|
|
||
|
# Создание очереди
|
||
|
channel.queue_declare(queue='consumer2_queue')
|
||
|
|
||
|
# Привязка очереди
|
||
|
channel.queue_bind(exchange='beauty_salon_events', queue='consumer2_queue')
|
||
|
|
||
|
channel.basic_consume(queue='consumer2_queue', on_message_callback=callback, auto_ack=True)
|
||
|
|
||
|
print('Consumer 2 начал ожидать сообщения...')
|
||
|
channel.start_consuming()
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
consume_events_2()
|