DAS_2024_1/karamushko_maxim_lab_4/Publisher.py

22 lines
698 B
Python
Raw Normal View History

2024-12-23 15:45:25 +04:00
import random
import time
import pika
if __name__ == '__main__':
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='logs', exchange_type='fanout')
try:
while True:
message = random.choice([
"Пришел клиент",
"Ушел клиент",
"Клиент недоволен",
"Вы разбудили клиента"
])
channel.basic_publish(exchange='logs', routing_key='', body=message)
time.sleep(1)
except KeyboardInterrupt:
connection.close()