2024-10-23 14:11:04 +04:00
|
|
|
import pika
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
def callback(ch, method, properties, body):
|
|
|
|
print(f'Receiver 1: получено сообщение. {body.decode()}')
|
|
|
|
|
2024-10-23 15:56:48 +04:00
|
|
|
time.sleep(3)
|
2024-10-23 14:11:04 +04:00
|
|
|
|
|
|
|
print('Receiver 1 закончил обработку')
|
|
|
|
|
|
|
|
|
|
|
|
def consume_events_1():
|
2024-10-23 15:56:48 +04:00
|
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost', port=5672, credentials=pika.PlainCredentials("user", "password")))
|
2024-10-23 14:11:04 +04:00
|
|
|
channel = connection.channel()
|
|
|
|
|
|
|
|
channel.queue_declare(queue='receiver1_queue')
|
|
|
|
channel.queue_bind(exchange='greenhouse_events', queue='receiver1_queue')
|
|
|
|
|
|
|
|
channel.basic_consume(queue='receiver1_queue', on_message_callback=callback, auto_ack=True)
|
|
|
|
|
|
|
|
print('Ожидание сообщения...')
|
|
|
|
channel.start_consuming()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
consume_events_1()
|