RocketMQ :
由阿里巴巴团队开发,贡献给了apache;
是一个队列模型的消息中间件;
具有高性能、高可靠、高实时、分布式的特点;
它是一个采用 Java 语言开发的分布式的消息系统.
下载
wget -c https://archive.apache.org/dist/rocketmq/4.5.1/rocketmq-all-4.5.1-bin-release.zip
unzip rocketmq-all-4.5.1-bin-release.zip -d /usr/local/
mv /usr/local/rocketmq-all-4.5.1-bin-release /usr/local/docker_rocketmq
cd /usr/local/docker_rocketmq
配置
编辑runbroker.sh和runserver.sh修改默认JVM大小
vim bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
vim bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
vim conf/broker.conf
brokerIP1 = 192.168.0.60#增加这一行
运行
docker run -itd --privileged --restart=always \
-v /usr/local/docker_rocketmq:/usr/local/rocketmq \
-p 10909-10912:10909-10912 -p 9876:9876 \
--name=rocketmq centos7_ssh:latest /usr/sbin/init
注:容器中要放一份jdk1.8,这里就省略了
/etc/profile
export PATH=$PATH:/usr/local/jdk/bin
export JAVA_HOME="/usr/local/jdk"
docker exec -it rocketmq bash
chmod a+x /etc/rc.d/rc.local
vim /etc/rc.local
source /etc/profile
nohup sh /usr/local/rocketmq/bin/mqnamesrv >/usr/local/rocketmq/mqnamesrv.out &
nohup sh /usr/local/rocketmq/bin/mqbroker -n 192.168.0.60:9876 -c /usr/local/rocketmq/conf/broker.conf >/usr/local/rocketmq/mqbroker.out &
exit
docker restart rocketmq
测试:
接收端/server端
export NAMESRV_ADDR=192.168.0.60:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
09:24:06.628 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
Consumer Started.
发送端
export NAMESRV_ADDR=192.168.0.60:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
#可以把rocketmq目录复制到其他机器上执行
测试结果
发送端
......
pic=TopicTest, brokerName=broker-a, queueId=3], queueOffset=498]
SendResult [sendStatus=SEND_OK, msgId=AC11000120A25E2DE80C7A14CA8703E3, offsetMsgId=C0A8003C00002A9F0000000000057DE7, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=0], queueOffset=498]
SendResult [sendStatus=SEND_OK, msgId=AC11000120A25E2DE80C7A14CA8803E4, offsetMsgId=C0A8003C00002A9F0000000000057E9B, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=1], queueOffset=499]
SendResult [sendStatus=SEND_OK, msgId=AC11000120A25E2DE80C7A14CA8903E5, offsetMsgId=C0A8003C00002A9F0000000000057F4F, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=2], queueOffset=499]
SendResult [sendStatus=SEND_OK, msgId=AC11000120A25E2DE80C7A14CA8B03E6, offsetMsgId=C0A8003C00002A9F0000000000058003, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=3], queueOffset=499]
SendResult [sendStatus=SEND_OK, msgId=AC11000120A25E2DE80C7A14CA8F03E7, offsetMsgId=C0A8003C00002A9F00000000000580B7, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=0], queueOffset=499]
16:56:22.935 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[192.168.0.60:9876] result: true
16:56:22.936 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[192.168.0.60:10911] result: true
接收端
......
ConsumeMessageThread_16 Receive New Messages: [MessageExt [queueId=1, storeSize=180, queueOffset=499, sysFlag=0, bornTimestamp=1656060982920, bornHost=/192.168.0.245:56102, storeTimestamp=1656060828756, storeHost=/192.168.0.60:10911, msgId=C0A8003C00002A9F0000000000057E9B, commitLogOffset=360091, bodyCRC=917938826, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=500, CONSUME_START_TIME=1656060828757, UNIQ_KEY=AC11000120A25E2DE80C7A14CA8803E4, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 57, 54], transactionId='null'}]]
ConsumeMessageThread_3 Receive New Messages: [MessageExt [queueId=2, storeSize=180, queueOffset=499, sysFlag=0, bornTimestamp=1656060982921, bornHost=/192.168.0.245:56102, storeTimestamp=1656060828757, storeHost=/192.168.0.60:10911, msgId=C0A8003C00002A9F0000000000057F4F, commitLogOffset=360271, bodyCRC=1102156316, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=500, CONSUME_START_TIME=1656060828758, UNIQ_KEY=AC11000120A25E2DE80C7A14CA8903E5, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 57, 55], transactionId='null'}]]
ConsumeMessageThread_12 Receive New Messages: [MessageExt [queueId=3, storeSize=180, queueOffset=499, sysFlag=0, bornTimestamp=1656060982923, bornHost=/192.168.0.245:56102, storeTimestamp=1656060828758, storeHost=/192.168.0.60:10911, msgId=C0A8003C00002A9F0000000000058003, commitLogOffset=360451, bodyCRC=1359908749, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=500, CONSUME_START_TIME=1656060828763, UNIQ_KEY=AC11000120A25E2DE80C7A14CA8B03E6, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 57, 56], transactionId='null'}]]
ConsumeMessageThread_15 Receive New Messages: [MessageExt [queueId=0, storeSize=180, queueOffset=499, sysFlag=0, bornTimestamp=1656060982927, bornHost=/192.168.0.245:56102, storeTimestamp=1656060828763, storeHost=/192.168.0.60:10911, msgId=C0A8003C00002A9F00000000000580B7, commitLogOffset=360631, bodyCRC=638172955, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=500, CONSUME_START_TIME=1656060828763, UNIQ_KEY=AC11000120A25E2DE80C7A14CA8F03E7, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 57, 57], transactionId='null'}]]
-------------------end