31 lines
864 B
Python
31 lines
864 B
Python
import random
|
|
import pika
|
|
import time
|
|
|
|
EXCHANGE = 'report_events'
|
|
EVENTS = [
|
|
"Создать отчет трат",
|
|
"Создать отчет пополнений",
|
|
"Создать отчет смещения относительно плана расходов",
|
|
]
|
|
|
|
def publish(channel, exchange, event):
|
|
channel.basic_publish(exchange=exchange, routing_key='', body=event)
|
|
print(f'[x] PUBLISHED: {event}')
|
|
time.sleep(1)
|
|
|
|
def run():
|
|
# Подключение
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
|
|
channel = connection.channel()
|
|
channel.exchange_declare(exchange=EXCHANGE, exchange_type='fanout')
|
|
|
|
# Публикация
|
|
while True:
|
|
event = EVENTS[random.randint(0, len(EVENTS) - 1)]
|
|
publish(channel, EXCHANGE, event)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run()
|