DAS_2023_1/antonov_dmitry_lab4/rabbitmq/consumer2.py
2023-12-05 12:35:35 +04:00

27 lines
830 B
Python

import pika
def callback(ch, method, properties, body):
print("Врач 2 принимает пациента '{}'".format(body.decode()))
def consume_messages():
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
exchange_name = 'logs'
channel.queue_declare(queue='example_queue')
channel.queue_bind(exchange=exchange_name, queue='example_queue')
channel.basic_consume(queue='example_queue', on_message_callback=callback, auto_ack=True)
print(' Врач 2 ожидает пациента')
try:
channel.start_consuming()
except KeyboardInterrupt:
print('Врач 2 прекращает прием')
channel.stop_consuming()
connection.close()
if __name__ == '__main__':
consume_messages()