1? 拉取rocketmq镜像
root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]# docker pull rocketmqinc/rocketmq
Using default tag: latest
latest: Pulling from rocketmqinc/rocketmq
a02a4930cb5d: Pull complete
90eb47c86343: Pull complete
43bf660f95f6: Pull complete
7f5ca7a20245: Pull complete
707a618112e3: Pull complete
4b527473eafb: Pull complete
fedd1d06c8ba: Pull complete
27782fcf3aef: Pull complete
Digest: sha256:b08556227ad8d169b7927f4c48335877cb10060e6781374ce5a644ea29f6fbe1
Status: Downloaded newer image for rocketmqinc/rocketmq:latest
docker.io/rocketmqinc/rocketmq:latest
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
2? 使用容器卷挂载,把log和data目录挂载出来
[root@iZwz9fg6yybg15l4x7kkmyZ ~]# mkdir -p /docker/rocketmq/data/namesrv/logs /docker/rocketmq/data/namesrv/ store
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
?
3? 启动nameser并查看
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]# docker run -d \
> --restart=always \
> --name rmqnamesrv \
> -p 9876:9876 \
> -v /docker/rocketmq/data/namesrv/logs:/root/logs \
> -v /docker/rocketmq/data/namesrv/store:/root/store \
> -e "MAX_POSSIBLE_HEAP=100000000" \
> rocketmqinc/rocketmq \
> sh mqnamesrv
df051a95eab7ed2b1cd7a8c3f6f11178e6dc7de527126b00bffa887c2837421f
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
df051a95eab7 rocketmqinc/rocketmq "sh mqnamesrv" 5 seconds ago Up 5 seconds 10909/tcp, 0.0.0.0:9876-> 9876/tcp, 10911/tcp rmqnamesrv
652a79dc9cee centos "/bin/bash" 2 weeks ago Up 2 weeks centos02
18a95119e647 centos "/bin/bash" 2 weeks ago Up 2 weeks centos01
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
启动参数说明:
-p? 表示的是将容器内的id
--name? 指定容器名称
sh? mqnamesrv 启动namesrv
4? 编写broker配置文件
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmqlogs]#
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmqlogs]# cat /docker/rocketmq/conf/broker.conf
# 所属集群名称,如果节点较多可以配置多个
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
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmqlogs]#
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmqlogs]#
5? 启动broker
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]# vi /docker/rocketmq/conf/broker.conf
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]# docker run -d \
> --restart=always \
> --name rmqbroker \
> --link rmqnamesrv:namesrv \
> -p 10911:10911 \
> -p 10909:10909 \
> -v /docker/rocketmq/data/broker/logs:/root/logs \
> -v /docker/rocketmq/data/broker/store:/root/store \
> -v /docker/rocketmq/conf/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf \
> -e "NAMESRV_ADDR=namesrv:9876" \
> -e "MAX_POSSIBLE_HEAP=200000000" \
> rocketmqinc/rocketmq \
> sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf
7ecb01559826d4311aec3954f2ba2860b26efd90e0936f8345e985961e695bc8
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
6? 拉取rocketmq-console并启动
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]# docker pull pangliang/rocketmq-console-ng
Using default tag: latest
latest: Pulling from pangliang/rocketmq-console-ng
e7c96db7181b: Pull complete
f910a506b6cb: Pull complete
b6abafe80f63: Pull complete
373993838a5d: Pull complete
Digest: sha256:630eb2fb9f144637bb6f77af37e23426e0c0596b0d46873f1c921f8f6c4aa17a
Status: Downloaded newer image for pangliang/rocketmq-console-ng:latest
docker.io/pangliang/rocketmq-console-ng:latest
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]# docker run -d \
> --restart=always \
> --name rmqadmin \
> -e "JAVA_OPTS=-Drocketmq.namesrv.addr=172.17.0.2:9876 \
> -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
> -p 9999:8080 \
> pangliang/rocketmq-console-ng
ce9c4f09ef4d09469625ae5c699f3e9a35b3a63db681b0c10883a017034488b0
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ce9c4f09ef4d pangliang/rocketmq-console-ng "sh -c 'java $JAVA_O…" 5 seconds ago Up 4 seconds 0.0.0. 0:9999->8080/tcp rmqadmin
7ecb01559826 rocketmqinc/rocketmq "sh mqbroker -c /opt…" 15 minutes ago Up 15 minutes 0.0.0. 0:10909->10909/tcp, 9876/tcp, 0.0.0.0:10911->10911/tcp rmqbroker
df051a95eab7 rocketmqinc/rocketmq "sh mqnamesrv" 25 minutes ago Up 25 minutes 10909/ tcp, 0.0.0.0:9876->9876/tcp, 10911/tcp rmqnamesrv
652a79dc9cee centos "/bin/bash" 2 weeks ago Up 2 weeks centos02
18a95119e647 centos "/bin/bash" 2 weeks ago Up 2 weeks centos01
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
[root@iZwz9fg6yybg15l4x7kkmyZ ~]#
7? 然后通过网页访问rocketmq-console的ip:port
写个python的测试代码测试下
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]# cat produce.py
from rocketmq.client import Producer, Message
import json
producer = Producer('PID-test')
producer.set_namesrv_addr('172.17.0.2:9876') #rocketmq队列接口地址(服务器ip:port)
producer.start()
msg_body = {"id":"001","name":"test_mq","message":"abcdefgwzq11111"}
ss = json.dumps(msg_body).encode('utf-8')
msg = Message('RMQ_SYS_TRANS_HALF_TOPIC') #topic名称
msg.set_keys('1234567911111')
msg.set_tags('2')
msg.set_body(ss) #message body
retmq = producer.send_sync(msg)
print(retmq.status, retmq.msg_id, retmq.offset)
producer.shutdown()
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]#
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]#
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]# cat consumer.py
# 使用PullConsumer时
from rocketmq.client import PullConsumer
consumer = PullConsumer('CID_test')
consumer.set_namesrv_addr('172.17.0.2:9876')
consumer.start()
for msg in consumer.pull('RMQ_SYS_TRANS_HALF_TOPIC'):
print(msg.id, msg.body)
consumer.shutdown()
# PushConsumer与此类似
from rocketmq.client import PushConsumer
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]#
?
执行下脚本并查看消息
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]#
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]# python3 produce.py
SendStatus.OK 0100A8C0000066E300007473F5700100 4
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]#
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]#
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]#
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]# python3 consumer.py
0100A8C00000D9900000BE52F2700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C00000D9900000BE52F2700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C00000D9900000BE52F2700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C00000D9900000BE52F2700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C0000066E300007473F5700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C00000D9900000BE52F2700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C0000066E300007473F5700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C00000D9900000BE52F2700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C0000066E300007473F5700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C00000D9900000BE52F2700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
0100A8C0000066E300007473F5700100 b'{"id": "001", "name": "test_mq", "message": "abcdefg"}'
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]#
[root@iZwz9fg6yybg15l4x7kkmyZ rocketmq]#
?
|