简介
https://rocketmq.apache.org/
下载
可以使用备用地址下载
[root@host125 install]# pwd
/opt/install
[root@host125 install]# wget https://dlcdn.apache.org/rocketmq/4.9.3/rocketmq-all-4.9.3-bin-release.zip
解压启动
rocketmq启动依赖jdk,因笔者已安装,此处不再提供jdk安装步骤。
[root@host125 install]# unzip rocketmq-all-4.9.3-bin-release.zip
....
[root@host125 install]# cd rocketmq-4.9.3/
[root@host125 rocketmq-4.9.3]# ls
benchmark bin conf lib LICENSE NOTICE README.md
- 启动namesrv
[root@host125 rocketmq-4.9.3]# cd bin
[root@host125 bin]# nohup sh mqnamesrv &
[1] 6120
[root@host125 bin]# nohup: 忽略输入并把输出追加到'nohup.out'
[root@host125 bin]# tail -f ~/logs/rocketmqlogs/namesrv.log
2022-05-27 21:40:17 INFO main - tls.client.authServer = false
2022-05-27 21:40:17 INFO main - tls.client.trustCertPath = null
2022-05-27 21:40:18 INFO main - Using JDK SSL provider
2022-05-27 21:40:19 INFO main - SSLContext created for server
2022-05-27 21:40:19 INFO main - Try to start service thread:FileWatchService started:false lastThread:null
2022-05-27 21:40:19 INFO NettyEventExecutor - NettyEventExecutor service started
2022-05-27 21:40:19 INFO main - The Name Server boot success. serializeType=JSON
2022-05-27 21:40:19 INFO FileWatchService - FileWatchService service started
2022-05-27 21:41:19 INFO NSScheduledThread1 - --------------------------------------------------------
2022-05-27 21:41:19 INFO NSScheduledThread1 - configTable SIZE: 0
- 启动broker
启动前需修改java启动参数,默认的java虚拟机内存8G过大,笔者改成了256m
[root@host125 bin]# vi runbroker.sh
#修改项
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m"
[root@host125 bin]# nohup sh mqbroker -n localhost:9876 &
[2] 6240
[root@host125 bin]# nohup: 忽略输入并把输出追加到'nohup.out'
[root@host125 bin]# tail -f ~/logs/rocketmqlogs/broker.log
2022-05-27 21:46:18 INFO main - Try to start service thread:FileWatchService started:false lastThread:null
2022-05-27 21:46:18 INFO FileWatchService - FileWatchService service started
2022-05-27 21:46:18 INFO main - Try to start service thread:PullRequestHoldService started:false lastThread:null
2022-05-27 21:46:18 INFO PullRequestHoldService - PullRequestHoldService service started
2022-05-27 21:46:18 INFO main - Try to start service thread:TransactionalMessageCheckService started:false lastThread:null
2022-05-27 21:46:19 INFO brokerOutApi_thread_1 - register broker[0]to name server localhost:9876 OK
2022-05-27 21:46:19 INFO main - The broker[host125, 192.168.220.125:10911] boot success. serializeType=JSON and name server is localhost:9876
2022-05-27 21:46:28 INFO BrokerControllerScheduledThread1 - dispatch behind commit log 0 bytes
2022-05-27 21:46:28 INFO BrokerControllerScheduledThread1 - Slave fall behind master: 0 bytes
2022-05-27 21:46:29 INFO brokerOutApi_thread_2 - register broker[0]to name server localhost:9876 OK
发送和接收消息
[root@host125 bin]# export NAMESRV_ADDR=localhost:9876
[root@host125 bin]# ./tools.sh org.apache.rocketmq.example.quickstart.Producer
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.InternalThreadLocalMap).
RocketMQLog:WARN Please initialize the logger system properly.
SendResult [sendStatus=SEND_OK, msgId=7F00000119F308EFB84688071D120000, offsetMsgId=C0A8DC7D00002A9F0000000000017392, messageQueue=MessageQueue [topic=TopicTest, brokerName=host125, queueId=2], queueOffset=124]
SendResult [sendStatus=SEND_OK, msgId=7F00000119F308EFB84688071D210001, offsetMsgId=C0A8DC7D00002A9F0000000000017450, messageQueue=MessageQueue [topic=TopicTest, brokerName=host125, queueId=3], queueOffset=124]
[root@host125 bin]# ./tools.sh org.apache.rocketmq.example.quickstart.Consumer
使用mqdamin命令查看topic的相关信息
[root@host125 bin]# ./mqadmin help topicList
usage: mqadmin topicList [-c] [-h] [-n <arg>]
-c,--clusterModel clusterModel
-h,--help Print help
-n,--namesrvAddr <arg> Name server address list, eg: '192.168.0.1:9876;192.168.0.2:9876'
[root@host125 bin]# ./mqadmin topicList -n 127.0.0.1:9876
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.InternalThreadLocalMap).
RocketMQLog:WARN Please initialize the logger system properly.
host125
SCHEDULE_TOPIC_XXXX
RMQ_SYS_TRANS_HALF_TOPIC
DefaultCluster_REPLY_TOPIC
%RETRY%please_rename_unique_group_name_4
BenchmarkTest
OFFSET_MOVED_EVENT
TopicTest
TBW102
SELF_TEST_TOPIC
DefaultCluster
[root@host125 bin]# ./mqadmin help topicStatus
usage: mqadmin topicStatus [-h] [-n <arg>] -t <arg>
-h,--help Print help
-n,--namesrvAddr <arg> Name server address list, eg: '192.168.0.1:9876;192.168.0.2:9876'
-t,--topic <arg> topic name
[root@host125 bin]# ./mqadmin topicStatus -n 127.0.0.1:9876 -t TopicTest
RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.InternalThreadLocalMap).
RocketMQLog:WARN Please initialize the logger system properly.
#Broker Name #QID #Min Offset #Max Offset #Last Updated
host125 0 0 160 2022-05-27 09:56:08,021
host125 1 0 160 2022-05-27 09:56:08,023
host125 2 0 161 2022-05-27 09:56:08,034
host125 3 0 161 2022-05-27 09:56:08,037
[root@host125 bin]#
停止broker和namesrv
[root@host125 bin]# ./mqshutdown broker
The mqbroker(6268) is running...
Send shutdown request to mqbroker(6268) OK
[root@host125 bin]# ./mqshutdown namesrv
The mqnamesrv(6144) is running...
Send shutdown request to mqnamesrv(6144) OK
[2]+ 退出 143 nohup sh mqbroker -n localhost:9876
[root@host125 bin]#