RocketMQ是由阿里巴巴自研并捐赠给Apahche基金会,具备低延迟、高并发、高可用、高可靠,支持万亿级数据红枫的分布式消息中间件。
RocketMQ 特点
- 是一个队列模型的消息中间件,具有高性能、高可靠、高实时、分布式等特点
- Producer、Consumer、队列都可以分布式
- Producer 向一些队列轮流发送消息,队列集合称为 Topic,Consumer 如果做广播消费,则一个 Consumer 实例消费这个 Topic 对应的所有队列,如果做集群消费,则多个 Consumer 实例平均消费这个 Topic 对应的队列集合
- 能够保证严格的消息顺序
- 支持拉(pull)和推(push)两种消息模式
- 高效的订阅者水平扩展能力
- 实时的消息订阅机制
- 亿级消息堆积能力
- 支持多种消息协议,如 JMS、OpenMessaging 等
- 较少的依赖
Docker中安装RocketMQ的步骤
拉取镜像
# docker search rocketmq
# docker pull foxiswho/rocketmq:4.8.0
启动 NameServer
# docker run -d --name rmqnamesrver -e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" -p 9876:9876 foxiswho/rocketmq:4.8.0 sh mqnamesrv
启动 Broker
创建挂载目录
# mkdir -p /data/docker/rocketmq/logs
# mkdir -p /data/docker/rocketmq/store
# chmod -R 777 /data
启动 Broker
# docker run -d -v /data/docker/rocketmq/logs:/home/rocketmq/logs -v /data/docker/rocketmq/store:/home/rocketmq/store
--name rmqbroker
-e "NAMESRV_ADDR=[namserver ip地址]:9876"
-e ”JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m"
-p 10911:10911
foxiswho/rocketmq:4.8.0
sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
对应windows命令:
# docker run -d -v D:\DockerData\data\rocketmq\logs:/home/rocketmq/logs -v D:\DockerData\data\rocketmq\
store:/home/rocketmq/store --name rmqbroker -e "NAMESERV_ADDR=127.0.0.1:9876" -e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128
m" -p 10911:10911 foxiswho/rocketmq:4.8.0 sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
注意:sh mqbroker -c
后的路径是否正确,当启动后要进入容器在 broker.conf 中配置上 NameServer 的 ip 信息,将 broker 注册到 NameServer。
启动 Rocketmq-console 控制台
# docker search rocketmq-console-ng
# docker pull styletang/rocketmq-console-ng
# docker run --name rmqconsole
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=[namserver ip]:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
-p 10100:8080 -t styletang/rocketmq-console-ng
开放端口 fire-cmd --zone=public --add-port=10100/tcp --permanent
浏览器访问:ip地址:10100
通过 docker-compose 方式安装
rocketmq.yml文件:
version: '3'
services:
namesrv:
image: foxiswho/rocketmq:4.8.0
container_name: rmqnamesrver
ports:
- "9876:9876"
environment:
JAVA_OPT_EXT: "-Xms512M -Xmx512M -Xmn128m"
command: sh mqnamesrv
broker:
image: foxiswho/rocketmq:4.8.0
container_name: rmqbroker
ports:
- "10911:10911"
environment:
NAMESERV_ADDR: "127.0.0.1:9876"
JAVA_OPT_EXT: "-Xms512M -Xmx512M -Xmn128m"
volumes:
- D:\DockerData\data\rocketmq\logs:/home/rocketmq/logs
- D:\DockerData\data\rocketmq\store:/home/rocketmq/store
command: sh mqbroker -n namesrv:9876 -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
depends_on:
- namesrv
mqconsole:
image: styletang/rocketmq-console-ng
container_name: rmqconsole
ports:
- "10100:8080"
environment:
JAVA_OPTS: -Drocketmq.config.namesrvAddr=namesrv:9876 -Drocketmq.config.isVIPChannel=false
depends_on:
- namesrv
执行命令一键生成 docker 容器
# docker compose -f [local_path]\rocketmq-console-ng.yml -p rocketmq up -d
[+] Running 4/4
- Network rocketmq_default Created 0.1s
- Container rmqnamesrver Started 1.0s
- Container rmqbroker Started 2.1s
- Container rmqconsole Started 2.2s
效果图:
RocketMQ-Docker-compose
网友评论