forked from Alexey/DAS_2023_1
21 lines
896 B
Python
21 lines
896 B
Python
|
import pika
|
||
|
import time
|
||
|
|
||
|
def publish_message(message):
|
||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(
|
||
|
host='localhost', # RabbitMQ server hostname
|
||
|
port=15672, # RabbitMQ server port
|
||
|
credentials=pika.PlainCredentials('guest', 'guest') # credentials
|
||
|
))
|
||
|
channel = connection.channel()
|
||
|
channel.queue_declare(queue='example_queue')
|
||
|
channel.basic_publish(exchange='', routing_key='example_queue', body=message)
|
||
|
# Отдаем сообщение в 'logs' exchange каждую секунду
|
||
|
while True:
|
||
|
message = "Пациент прибыл" # Сообщение
|
||
|
channel.basic_publish(exchange='logs', routing_key='', body=message)
|
||
|
print(f" [x] Отправлено сообщение: {message}")
|
||
|
time.sleep(1)
|
||
|
print(" [x] Отправлено '{}'".format(message))
|
||
|
connection.close()
|