forked from Alexey/DAS_2024_1
28 lines
898 B
Python
28 lines
898 B
Python
|
import pika
|
||
|
import time
|
||
|
|
||
|
def callback(ch, method, properties, body):
|
||
|
print(f'Consumer 1 получил сообщение: {body.decode()}')
|
||
|
|
||
|
# Время задержки по условию
|
||
|
time.sleep(2)
|
||
|
|
||
|
print('Consumer 1 закончил обработку')
|
||
|
|
||
|
def consume_events_1():
|
||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
||
|
channel = connection.channel()
|
||
|
|
||
|
# Создание очереди
|
||
|
channel.queue_declare(queue='consumer1_queue')
|
||
|
# Привязка очереди
|
||
|
channel.queue_bind(exchange='beauty_salon_events', queue='consumer1_queue')
|
||
|
|
||
|
channel.basic_consume(queue='consumer1_queue', on_message_callback=callback, auto_ack=True)
|
||
|
|
||
|
print('Consumer 1 начал ожидать сообщения...')
|
||
|
channel.start_consuming()
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
consume_events_1()
|