26 lines
786 B
Python
26 lines
786 B
Python
import pika
|
|
import time
|
|
import random
|
|
|
|
def publish_event(channel, exchange_name):
|
|
events = ["пришёл заказ", "сообщение от пользователя", "необходимо создать отчёт"]
|
|
while True:
|
|
event = random.choice(events)
|
|
channel.basic_publish(exchange=exchange_name, routing_key='', body=event)
|
|
print(f"Отправлено событие: {event}")
|
|
time.sleep(3)
|
|
|
|
def main():
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
|
|
channel = connection.channel()
|
|
|
|
exchange_name = 'logs'
|
|
channel.exchange_declare(exchange=exchange_name, exchange_type='fanout')
|
|
|
|
publish_event(channel, exchange_name)
|
|
|
|
connection.close()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|