DmitriyAntonov 60ff69f12d good start
2023-12-04 20:01:33 +04:00

24 lines
808 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()