20 lines
737 B
Python
20 lines
737 B
Python
import pika
|
|
import time
|
|
|
|
|
|
def publish_messages():
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
|
|
channel = connection.channel()
|
|
|
|
exchange_name = 'logs'
|
|
channel.exchange_declare(exchange=exchange_name, exchange_type='fanout')
|
|
channel.queue_declare(queue='example_queue')
|
|
# Отдаем сообщение в 'logs' exchange каждую секунду
|
|
while True:
|
|
message = "Пациент прибыл" # Сообщение
|
|
channel.basic_publish(exchange='logs', routing_key='', body=message)
|
|
print(f"Отправлено сообщение: {message}")
|
|
time.sleep(1)
|
|
print("Отправлено '{}'".format(message))
|
|
connection.close()
|