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