# A three-node KubeMQ cluster on one host, with the Kafka endpoint reachable from the host.
#
#   export KUBEMQ_LICENSE_KEY=<your key>
#   docker compose -f docker-compose-cluster.yml up -d
#
# Bring all three up together: a node waits for two of three to agree before it finishes booting.
# Full explanation: https://docs.kubemq.io/deploy/docker-cluster
services:

  kubemq-next-0:
    image: europe-docker.pkg.dev/kubemq/images/kubemq-next:latest
    container_name: kubemq-next-0
    hostname: kubemq-next-0
    environment:
      - KUBEMQ_LICENSE_KEY=${KUBEMQ_LICENSE_KEY:?set KUBEMQ_LICENSE_KEY in your shell}
      - HOST=kubemq-next-0
      - CLUSTER_ENABLE=true
      - CLUSTER_NAME=kubemq-next
      - CLUSTER_PORT=5228
      - CLUSTER_ROUTES=kubemq-next-0:5228,kubemq-next-1:5228,kubemq-next-2:5228
      - CLUSTER_REPLICATION_REPLICA_ID=1
      - CLUSTER_REPLICATION_PEERS=1@kubemq-next-0:6800,2@kubemq-next-1:6800,3@kubemq-next-2:6800
      - CONNECTORS_KAFKA_PORT=19092
      - CONNECTORS_KAFKA_ADVERTISED_HOST=127.0.0.1
      - CONNECTORS_KAFKA_PEERS=1@127.0.0.1:19092,2@127.0.0.1:19093,3@127.0.0.1:19094
    volumes:
      - store_next_0:/kubemq/store
    ports:
      - "50000:50000"   # gRPC
      - "8080:8080"     # API & dashboard
      - "19092:19092"   # Kafka
    networks: [net_next]

  kubemq-next-1:
    image: europe-docker.pkg.dev/kubemq/images/kubemq-next:latest
    container_name: kubemq-next-1
    hostname: kubemq-next-1
    environment:
      - KUBEMQ_LICENSE_KEY=${KUBEMQ_LICENSE_KEY:?set KUBEMQ_LICENSE_KEY in your shell}
      - HOST=kubemq-next-1
      - CLUSTER_ENABLE=true
      - CLUSTER_NAME=kubemq-next
      - CLUSTER_PORT=5228
      - CLUSTER_ROUTES=kubemq-next-0:5228,kubemq-next-1:5228,kubemq-next-2:5228
      - CLUSTER_REPLICATION_REPLICA_ID=2
      - CLUSTER_REPLICATION_PEERS=1@kubemq-next-0:6800,2@kubemq-next-1:6800,3@kubemq-next-2:6800
      - CONNECTORS_KAFKA_PORT=19093
      - CONNECTORS_KAFKA_ADVERTISED_HOST=127.0.0.1
      - CONNECTORS_KAFKA_PEERS=1@127.0.0.1:19092,2@127.0.0.1:19093,3@127.0.0.1:19094
    volumes:
      - store_next_1:/kubemq/store
    ports:
      - "50001:50000"
      - "8081:8080"
      - "19093:19093"
    networks: [net_next]

  kubemq-next-2:
    image: europe-docker.pkg.dev/kubemq/images/kubemq-next:latest
    container_name: kubemq-next-2
    hostname: kubemq-next-2
    environment:
      - KUBEMQ_LICENSE_KEY=${KUBEMQ_LICENSE_KEY:?set KUBEMQ_LICENSE_KEY in your shell}
      - HOST=kubemq-next-2
      - CLUSTER_ENABLE=true
      - CLUSTER_NAME=kubemq-next
      - CLUSTER_PORT=5228
      - CLUSTER_ROUTES=kubemq-next-0:5228,kubemq-next-1:5228,kubemq-next-2:5228
      - CLUSTER_REPLICATION_REPLICA_ID=3
      - CLUSTER_REPLICATION_PEERS=1@kubemq-next-0:6800,2@kubemq-next-1:6800,3@kubemq-next-2:6800
      - CONNECTORS_KAFKA_PORT=19094
      - CONNECTORS_KAFKA_ADVERTISED_HOST=127.0.0.1
      - CONNECTORS_KAFKA_PEERS=1@127.0.0.1:19092,2@127.0.0.1:19093,3@127.0.0.1:19094
    volumes:
      - store_next_2:/kubemq/store
    ports:
      - "50002:50000"
      - "8082:8080"
      - "19094:19094"
    networks: [net_next]

volumes:
  store_next_0:
  store_next_1:
  store_next_2:

networks:
  net_next:
    driver: bridge
