DAS_2023_1/kochkareva_elizaveta_lab_4/exercise-training/publisher.py
2024-01-19 11:39:52 +04:00

18 lines
548 B
Python

import pika
import random
import time
logs = ["started exercise", "finished exercise", "started training", "finished training"]
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
exchange_name = 'logs'
channel.exchange_declare(exchange=exchange_name, exchange_type='fanout')
print(' [*] Started. To exit press CTRL+C')
while 1:
log = random.choice(logs)
channel.basic_publish(exchange=exchange_name, routing_key='', body=log)
print(f" [x] Published: {log}")
time.sleep(1)