version: '3.8'

services:
  # RocketMQ NameServer Cluster
  namesrv-1:
    image: apache/rocketmq:5.0.0
    container_name: rocketmq-namesrv-1
    hostname: namesrv-1
    ports:
      - "9876:9876"
    environment:
      - NAMESRV_PORT=9876
      - JAVA_OPTS=-Duser.home=/home/rocketmq
    volumes:
      - ./data/namesrv-1:/home/rocketmq/store
      - ./config/namesrv-1.conf:/home/rocketmq/rocketmq-5.0.0/conf/namesrv-1.conf
    command: sh mqnamesrv
    networks:
      - rocketmq-net
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9876"]
      interval: 10s
      timeout: 5s
      retries: 5

  namesrv-2:
    image: apache/rocketmq:5.0.0
    container_name: rocketmq-namesrv-2
    hostname: namesrv-2
    ports:
      - "9877:9876"
    environment:
      - NAMESRV_PORT=9876
      - JAVA_OPTS=-Duser.home=/home/rocketmq
    volumes:
      - ./data/namesrv-2:/home/rocketmq/store
      - ./config/namesrv-2.conf:/home/rocketmq/rocketmq-5.0.0/conf/namesrv-2.conf
    command: sh mqnamesrv
    networks:
      - rocketmq-net
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9876"]
      interval: 10s
      timeout: 5s
      retries: 5

  # RocketMQ Broker Cluster
  broker-master-1:
    image: apache/rocketmq:5.0.0
    container_name: rocketmq-broker-master-1
    hostname: broker-master-1
    ports:
      - "10911:10911"
      - "10912:10912"
      - "10909:10909"
    environment:
      - NAMESRV_ADDR=namesrv-1:9876;namesrv-2:9876
      - JAVA_OPTS=-Duser.home=/home/rocketmq
      - JAVA_HOME=/usr/lib/jvm/java-17-openjdk
    volumes:
      - ./data/broker-master-1:/home/rocketmq/store
      - ./config/broker-master-1.conf:/home/rocketmq/rocketmq-5.0.0/conf/broker.conf
    command: sh mqbroker -c /home/rocketmq/rocketmq-5.0.0/conf/broker.conf
    depends_on:
      namesrv-1:
        condition: service_healthy
      namesrv-2:
        condition: service_healthy
    networks:
      - rocketmq-net

  broker-master-2:
    image: apache/rocketmq:5.0.0
    container_name: rocketmq-broker-master-2
    hostname: broker-master-2
    ports:
      - "10921:10911"
      - "10922:10912"
      - "10929:10909"
    environment:
      - NAMESRV_ADDR=namesrv-1:9876;namesrv-2:9876
      - JAVA_OPTS=-Duser.home=/home/rocketmq
      - JAVA_HOME=/usr/lib/jvm/java-17-openjdk
    volumes:
      - ./data/broker-master-2:/home/rocketmq/store
      - ./config/broker-master-2.conf:/home/rocketmq/rocketmq-5.0.0/conf/broker.conf
    command: sh mqbroker -c /home/rocketmq/rocketmq-5.0.0/conf/broker.conf
    depends_on:
      namesrv-1:
        condition: service_healthy
      namesrv-2:
        condition: service_healthy
    networks:
      - rocketmq-net

  broker-slave-1:
    image: apache/rocketmq:5.0.0
    container_name: rocketmq-broker-slave-1
    hostname: broker-slave-1
    ports:
      - "10931:10911"
      - "10932:10912"
      - "10939:10909"
    environment:
      - NAMESRV_ADDR=namesrv-1:9876;namesrv-2:9876
      - JAVA_OPTS=-Duser.home=/home/rocketmq
      - JAVA_HOME=/usr/lib/jvm/java-17-openjdk
    volumes:
      - ./data/broker-slave-1:/home/rocketmq/store
      - ./config/broker-slave-1.conf:/home/rocketmq/rocketmq-5.0.0/conf/broker.conf
    command: sh mqbroker -c /home/rocketmq/rocketmq-5.0.0/conf/broker.conf
    depends_on:
      namesrv-1:
        condition: service_healthy
      namesrv-2:
        condition: service_healthy
    networks:
      - rocketmq-net

  broker-slave-2:
    image: apache/rocketmq:5.0.0
    container_name: rocketmq-broker-slave-2
    hostname: broker-slave-2
    ports:
      - "10941:10911"
      - "10942:10912"
      - "10949:10909"
    environment:
      - NAMESRV_ADDR=namesrv-1:9876;namesrv-2:9876
      - JAVA_OPTS=-Duser.home=/home/rocketmq
      - JAVA_HOME=/usr/lib/jvm/java-17-openjdk
    volumes:
      - ./data/broker-slave-2:/home/rocketmq/store
      - ./config/broker-slave-2.conf:/home/rocketmq/rocketmq-5.0.0/conf/broker.conf
    command: sh mqbroker -c /home/rocketmq/rocketmq-5.0.0/conf/broker.conf
    depends_on:
      namesrv-1:
        condition: service_healthy
      namesrv-2:
        condition: service_healthy
    networks:
      - rocketmq-net

  # RocketMQ Dashboard (监控)
  rocketmq-dashboard:
    image: apache/rocketmq-dashboard:latest
    container_name: rocketmq-dashboard
    ports:
      - "8080:8080"
    environment:
      - JAVA_OPTS=-Dserver.port=8080
      - ROCKETMQ_CONFIG_NAMESRVADDR=namesrv-1:9876;namesrv-2:9876
      - ROCKETMQ_CONFIG_ISVIPCHANNEL=false
    depends_on:
      - namesrv-1
      - namesrv-2
    networks:
      - rocketmq-net

networks:
  rocketmq-net:
    driver: bridge
