import pika
import json
import time
import random

credentials = pika.PlainCredentials('guest', 'guest')
connection = pika.BlockingConnection(
  pika.ConnectionParameters(host='localhost', credentials=credentials))
channel = connection.channel()

channel.exchange_declare(exchange='order_events', exchange_type='fanout')

while True:
  event = {
    'event_type': 'order_created',
    'order_id': random.randint(1000, 9999),
    'customer_name': f'Клиент {random.randint(1, 100)}',
    'product_name': f'Товар {random.randint(1, 10)}',
    'quantity': random.randint(1, 10),
    'timestamp': time.time()
  }

  channel.basic_publish(
    exchange='order_events',
    routing_key='',
    body=json.dumps(event)
  )
  print(f'Опубликовано событие: {event}')
  time.sleep(1)

connection.close()