26 lines
917 B
Python
26 lines
917 B
Python
|
import pika
|
||
|
|
||
|
def callback(ch, method, properties, body):
|
||
|
print(" [x] Врач 1 принимает пациента '{}'".format(body.decode()))
|
||
|
|
||
|
def consume_messages():
|
||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(
|
||
|
host='localhost', # RabbitMQ server hostname
|
||
|
port=5672, # RabbitMQ server port
|
||
|
credentials=pika.PlainCredentials('guest', 'guest') # credentials
|
||
|
))
|
||
|
channel = connection.channel()
|
||
|
channel.queue_declare(queue='example_queue')
|
||
|
channel.basic_consume(queue='example_queue', on_message_callback=callback, auto_ack=True)
|
||
|
print(' [*] Врач 1 ожидает приема')
|
||
|
try:
|
||
|
channel.start_consuming()
|
||
|
except KeyboardInterrupt:
|
||
|
print('Прервано. Останавливаем прием...')
|
||
|
channel.stop_consuming()
|
||
|
connection.close()
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
consume_messages()
|
||
|
|