#!/bin/bash
# RocketMQ Topic Setup Script
# 用法: bash setup-topics.sh

# 主题列表
TOPICS=(
  "order-topic:8"           # 订单主题，8个队列
  "inventory-topic:8"      # 库存主题
  "finance-topic:8"         # 财务主题
  "notification-topic:4"   # 通知主题
  "payment-topic:8"         # 支付主题
  "warehouse-topic:4"       # 仓库主题
  "customer-topic:4"        # 客户主题
  "report-topic:2"          # 报表主题
)

# NameServer地址
NAMESRV_ADDR=${NAMESRV_ADDR:-"localhost:9876"}
export NAMESRV_ADDR

# 循环创建主题
for topic_info in "${TOPICS[@]}"; do
  topic=$(echo $topic_info | cut -d':' -f1)
  queues=$(echo $topic_info | cut -d':' -f2)
  
  echo "Creating topic: $topic with $queues queues..."
  
  # 使用 mqadmin 创建主题
  docker exec rocketmq-broker-master-1 sh mqadmin updateTopic \
    -n $NAMESRV_ADDR \
    -t $topic \
    -c rocketmq-cluster \
    -r $queues \
    -w $queues
  
  echo "Topic $topic created successfully!"
done

echo "All topics created!"
