DAS_2023_1/arutunyan_dmitry_lab_4/sushi-bar/publisher.py

19 lines
515 B
Python

import pika, time, random
logs = ["get address", "get order", "get pavement", "order done"]
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)