RocketMQ 配置及docker启动

# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = DefaultCluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-a
#0表示Master,大于0表示不同的slave
brokerId = 0
#表示几点做消息删除动作,默认是凌晨4点
deleteWhen = 04
#在磁盘上保留消息的时长,单位是小时
fileReservedTime = 48
#有三个值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步和异步表示Master和Slave之间同步数据的机制;
brokerRole = ASYNC_MASTER
#刷盘策略,取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要;
flushDiskType = ASYNC_FLUSH
# 设置broker节点所在服务器的ip地址
brokerIP1 = 127.0.0.1
# 磁盘使用达到95%之后,生产者再写入消息会报错 CODE: 14 DESC: service not available now, maybe disk full
diskMaxUsedSpaceRatio=95
autoCreateTopicEnable=true


#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#存储路径(这个路径开启了会启动不了,暂不知原因)
#storePathRootDir=/home/rocketmq/store
#commitLog 存储路径
storePathCommitLog=/home/rocketmq/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/home/rocketmq/store/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
#brokerRole=SYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
#flushDiskType=SYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

docker-compose参考

version : '3.8'
networks:
  test-networks:
    driver: bridge

services:

  test-mqnamesrv:
    container_name: test-mqnamesrv
    image: apache/rocketmq:4.9.2
    build:
      context: ./rocketmq
      dockerfile: dockerfile
    ports:
      - 9876:9876
    volumes:
      - ./rocketmq/logs:/home/rocketmq/logs
      - /etc/localtime:/etc/localtime
      - /etc/timezone/timezone:/etc/timezone
    networks:
      - test-networks
    command: 
      sh mqnamesrv

  test-mqbroker:
    container_name: test-mqbroker
    image: apache/rocketmq:4.9.2
    build:
      context: ./rocketmq
      dockerfile: dockerfile
    ports:
      - 10911:10911
      - 10909:10909
    environment:
      NAMESRV_ADDR: test-mqnamesrv:9876
    volumes:
      - ./rocketmq/conf/broker.conf:/home/rocketmq/conf/broker.conf
      - ./rocketmq/data/broker/logs:/home/rocketmq/logs
      - ./rocketmq/data/broker/store:/home/rocketmq/store
      - /etc/localtime:/etc/localtime
      - /etc/timezone/timezone:/etc/timezone
    depends_on:
      - test-mqnamesrv
    links:
      - "test-mqnamesrv:test-mqnamesrv"
    networks:
      - test-networks
    command: 
      sh mqbroker -n test-mqnamesrv:9876 -c /home/rocketmq/conf/broker.conf

  test-mqconsole:
    image: styletang/rocketmq-console-ng
    container_name: test-mqconsole
    ports:
      - 18080:8080
    depends_on:
      - test-mqnamesrv
      - test-mqbroker
    links:
      - "test-mqnamesrv:test-mqnamesrv"
      - "test-mqbroker:test-mqbroker"
    environment:
      JAVA_OPTS: 
        -Drocketmq.namesrv.addr=test-mqnamesrv:9876 
        -Dcom.rocketmq.sendMessageWithVIPChannel=false 
        -Drocketmq.config.loginRequired=false 
    volumes:
      - ./rocketmq/console/data:/tmp/rocketmq-console/data
    networks:
      - test-networks

      

注意,由于rocketmq启动后不是root用户,所以宿主机映射的目录需要设置777权限

chmod 777 -R ./rocketmq/data/broker/

用RocketMQ的时候,客户端与服务器端一定要使用相同的版本。否则可能会导致重启应用后重复消费的问题。

This entry was posted in 应用. Bookmark the permalink.

发表评论