RocketMQ搭建(本地環(huán)境)
1. 準備(本地環(huán)境)
host設置 (/etc/hosts)
127.0.0.1 host.docker.internal
目的:讓本地服務可以正常訪問服務
2. 啟動服務
broker.conf
#broker1服務器配置
brokerClusterName = DefaultCluster
#broker名稱赞厕,master和slave使用相同的名稱,表明他們的主從關系
brokerName = rocketmq-broker
#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消息寫入磁盤后才返回成功狀態(tài)嘹锁,async_flush不需要;
flushDiskType = ASYNC_FLUSH
#broker外網訪問的ip地址
brokerIP1 = host.docker.internal
#broker服務端口
listenPort = 10911
docker-compose.yaml
version: "3.3"
services:
rocketmq-namesrv:
image: apache/rocketmq:4.9.7
restart: always
container_name: rocketmq-namesrv
ports:
- "9876:9876"
volumes:
- ./logs/nameserver1:/home/rocketmq/logs/rocketmqlogs
command: sh mqnamesrv
networks:
- rocketmq
rocketmq-broker:
image: apache/rocketmq:4.9.7
restart: always
container_name: rocketmq-broker
ports:
- "10911:10911"
volumes:
- ./logs/broker:/home/rocketmq/logs/rocketmqlogs
- ./conf/broker.conf:/home/rocketmq/rocketmq-4.9.7/conf/broker.conf
environment:
TZ: Asia/Shanghai
NAMESRV_ADDR: "rocketmq-namesrv:9876"
JAVA_OPTS: "-Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.7/conf/broker.conf autoCreateTopicEnable=true &
depends_on:
- rocketmq-namesrv
networks:
- rocketmq
rocketmq-console:
image: apacherocketmq/rocketmq-console:2.0.0
restart: always
container_name: rocketmq-console
ports:
- "9090:8080"
environment:
JAVA_OPTS: -Drocketmq.namesrv.addr=rocketmq-namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
networks:
- rocketmq
depends_on:
- rocketmq-broker
networks:
rocketmq:
driver: bridge
啟動服務
docker-compose up -d
? docker-compose up -d
[+] Running 3/0
? Container rocketmq-namesrv Running 0.0s
? Container rocketmq-broker Running 0.0s
? Container rocketmq-console Running 0.0s