方案
RocketMQ是分布式的消息队列,所以有各种高性能,高可用的部署方案。
本文暂时不考虑高性能和高可用的部署方案。主要说明如果使用Docker部署RocketMQ。
本文将在Docker单台宿主机上部署:
- nameserver :消息服务器将结点及消息服务信息注册到该结点上,客户端也连接到该结点上,获取消息服务信息。
- broker:提供消息服务
- 通过rockermq-console对RocketMQ监控管理
- 部署一个mq的消息生产客户端
- 部署一个mq的消息消费客户端
Dockerfile说明
rocketmq源码工程中自带有一个工程rocketmq-externals中,有一个生成docker镜像的工程rocketmq-docker。
https://github.com/apache/rocketmq-externals/tree/master/rocketmq-docker
关于nameserver及server的部署基于该工程下的Dockerfile进行部署。
nameserver镜像生成脚本
# Start from a Java image.
FROM java:8
ARG version
# Rocketmq version
ENV ROCKETMQ_VERSION 4.2.0
# Rocketmq home
ENV ROCKETMQ_HOME /opt/rocketmq-${ROCKETMQ_VERSION}
WORKDIR ${ROCKETMQ_HOME}
RUN mkdir -p \
/opt/logs \
/opt/store \
/opt/conf
#这行代码进行了修改,基于本地的rocketmq编译包生成镜像,而不是通过网上下载。
ADD rocketmq-all-4.2.0-bin-release.zip rocketmq.zip
RUN unzip rocketmq.zip \
&& rm rocketmq.zip
RUN chmod +x bin/mqnamesrv
CMD cd ${ROCKETMQ_HOME}/bin && export JAVA_OPT=" -Duser.home=/opt" && sh mqnamesrv
EXPOSE 9876
VOLUME /opt/logs \
/opt/store \
/opt/conf
broker镜像生成脚本
FROM java:8
# Rocketmq version
ENV ROCKETMQ_VERSION 4.2.0
# Rocketmq home
ENV ROCKETMQ_HOME /opt/rocketmq-${ROCKETMQ_VERSION}
WORKDIR ${ROCKETMQ_HOME}
RUN mkdir -p \
/opt/logs \
/opt/store
ADD rocketmq-all-4.2.0-bin-release.zip rocketmq.zip
RUN unzip rocketmq.zip \
&& rm rocketmq.zip
RUN chmod +x bin/mqbroker
CMD cd ${ROCKETMQ_HOME}/bin && export JAVA_OPT=" -Duser.home=/opt" && sh mqbroker -n namesrv:9876
EXPOSE 10909 10911
VOLUME /opt/logs \
/opt/store
console镜像生成脚本
这里是在Apache开源后的,该控制台的代码管理地址
https://github.com/apache/incubator-rocketmq-externals/tree/master/rocketmq-console
基于工程源代码编译,生成工程jar包rocketmq-console-ng-1.0.0.jar (该工程是spring-boot工程,jar中内嵌servlet容器。)
FROM java:8
VOLUME /tmp
ADD rocketmq-console-ng-1.0.0.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar /app.jar" ]
生产方及消息方镜像
这两个镜像比较简单,工程本身就是以main运行的java工程。
可以参考该文章:https://blog.csdn.net/liulianglin/article/details/51787459
FROM java:8
VOLUME /tmp
#ADD mq-consumer.jar app.jar
ADD mq-producer.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar /app.jar" ]
docker-mopose
version: '2'
services:
namesrv:
image: going/rocketmq-namesrv:4.2.0
ports:
- 9876:9876
volumes:
- "E:/rocketmq/namesrv/master/logs:/opt/logs"
- "E:/rocketmq/namesrv/master/store:/opt/store"
broker:
image: going/rocketmq-broker:4.2.0
ports:
- 10909:10909
- 10911:10911
volumes:
- "E:/rocketmq/broker/master-1/logs:/opt/logs"
- "E:/rocketmq/broker/master-1/store:/opt/store"
links:
- namesrv:namesrv
console:
image: styletang/rocketmq-console-ng:latest
ports:
- "8080:8080"
links:
- namesrv:namesrv
environment:
JAVA_OPTS: -Drocketmq.config.namesrvAddr=namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
producer:
image: going/rocketmq-producer:4.1.0
links:
- namesrv:namesrv
consumer:
image: going/rocketmq-consumer:4.1.0
links:
- namesrv:namesrv
通过docker-compose运行,打开console界面,查看执行情况
http://127.0.0.1:8080/#/