DAS_2024_1/tukaeva_alfiya_lab_4/Publisher.py

17 lines
565 B
Python
Raw Permalink Normal View History

2024-10-20 19:04:32 +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(['SIGABRT', 'SIGALRM', 'SIGKILL', 'SIGSTOP', 'SIGTERM', 'SIGINT', 'SIGQUIT'])
channel.basic_publish(exchange='logs', routing_key='', body=message)
time.sleep(1)
except KeyboardInterrupt:
connection.close()