Rocketmq in Docker Compose

Posted on Jan 2, 2023
Create data dirs for docker
sudo mkdir -p /data/docker-vol/rmq/broker-{a,b}/logs
sudo mkdir -p /data/docker-vol/rmq/namesrv-{a,b}/{logs,store}
sudo chown -R 3000:3000 /data/docker-vol/rmq/

Directory strcuture

./conf
./conf/broker-a.conf
./conf/broker-b.conf
./docker-compose.yml

./docker-compose.yml

version: '3.1'

services:
  rmqnamesrv-a:
    container_name: rmqnamesrv-a
    image: apache/rocketmq:4.8.0
    ports:
      - 9876:9876
    volumes:
      - /data/docker-vol/rmq/namesrv-a/logs:/home/rocketmq/logs
    command: sh mqnamesrv
    deploy:
      resources:
        limits:
          memory: 1G

  rmqbroker-a:
    container_name: rmqbroker-a
    image: apache/rocketmq:4.8.0
    ports:
      - 10909:10909
      - 10911:10911
      - 10912:10912
    volumes:
      - /data/docker-vol/rmq/broker-a/logs:/home/rocketmq/logs
      - /data/docker-vol/rmq/broker-a/store:/home/rocketmq/store
      - ./conf/broker-a.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf
    command: sh mqbroker -c ../conf/broker.conf
    environment:
      - JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128M
      - NAMESRV_ADDR=rmqnamesrv-a:9876;rmqnamesrv-b:9876
    depends_on:
      - rmqnamesrv-a
    deploy:
      resources:
        limits:
          memory: 2G

  rmqnamesrv-b:
    container_name: rmqnamesrv-b
    image: apache/rocketmq:4.8.0
    ports:
      - 9877:9876
    volumes:
      - /data/docker-vol/rmq/namesrv-b/logs:/home/rocketmq/logs
    command: sh mqnamesrv
    deploy:
      resources:
        limits:
          memory: 1G

  rmqbroker-b:
    container_name: rmqbroker-b
    image: apache/rocketmq:4.8.0
    ports:
      - 10905:10905
      - 10907:10907
      - 10908:10908
    volumes:
      - /data/docker-vol/rmq/broker-b/logs:/home/rocketmq/logs
      - /data/docker-vol/rmq/broker-b/store:/home/rocketmq/store
      - ./conf/broker-b.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf
    command: sh mqbroker -c ../conf/broker.conf
    environment:
      - JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128M
      - NAMESRV_ADDR=rmqnamesrv-b:9876;rmqnamesrv-a:9876
    depends_on:
      - rmqnamesrv-b
    deploy:
      resources:
        limits:
          memory: 2G

  rmqconsole:
    image: styletang/rocketmq-console-ng
    ports:
      - 8180:8080
    environment:
      JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv-a:9876;rmqnamesrv-b:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
    depends_on:
      - rmqnamesrv-a
      - rmqnamesrv-b
    deploy:
      resources:
        limits:
          memory: 1G

.conf/broker-a.conf

brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
brokerIP1 = rmqbroker-a
deleteWhen = 04
fileReservedTime = 48
# namesrvAddr=rmqnamesrv-host-a:9876;rmqnamesrv-host-b:9877
listenPort = 10911
#Broker Role
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
autoCreateTopicEnable=false
#autoCreateSubscriptionGroup=false
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h 1d

.conf/broker-b.conf

brokerClusterName = DefaultCluster
brokerName = broker-b
brokerId = 0
brokerIP1 = rmqbroker-b
deleteWhen = 04
fileReservedTime = 48
# namesrvAddr=rmqnamesrv-host-b:9877;rmqnamesrv-host-a:9876
listenPort = 10907
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
autoCreateTopicEnable=false
#autoCreateSubscriptionGroup=false
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h 1d
Change config

conf/broker-a.conf

brokerIP1=IP_OF_HOST_MACHINE

conf/broker-b.conf

brokerIP1=IP_OF_HOST_MACHINE
Run service
docker compose up