DAS_2024_1/kurushina_ksenia_lab_4/publisher.py

28 lines
623 B
Python
Raw Normal View History

2024-12-09 19:44:24 +04:00
import pika
import time
def publish_events():
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='beauty_salon_events', exchange_type='fanout')
events = [
"5",
"4",
"3",
"2",
"1"
]
while True:
event = events[int(time.time()) % len(events)]
channel.basic_publish(exchange='beauty_salon_events', routing_key='', body=event)
print(f'Отправлено: {event}')
time.sleep(1)
if __name__ == "__main__":
publish_events()