0.下载解压
wget http://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.4.0/rocketmq-all-4.4.0-source-release.zip
unzip rocketmq-all-4.4.0-source-release.zip
1.编译
mvn -Prelease-all -DskipTests clean install -U
-P表示选择激活的profile
release-all查看distribution目录下的pom.xml
-DskipTests,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下
-Dmaven.test.skip=true,不执行测试用例,也不编译测试用例类
-U表示强制刷新本地仓库不存在release版和所有snapshots版本
把源码打包完成后,进入distribution/target目录,可以看到生成的包
2.解压源码编译的zip包
进入distribution/target目录,执行tar -zxvf rocketmq-4.5.2.tar.gz -C /usr/java,在java文件夹下面生成rocketmq-4.5.2
准备工作完成了,无需安装直接就可以使用了
3.启动namesrv服务
进入/usr/java/rocketmq-4.5.2目录执行nohup sh bin/mqnamesrv &
nohup命令:不挂断的运行
&指的是在后台运行
查看namesrv日志:tail -f ~/logs/rocketmqlogs/namesrv.log,成功会打印
main - The Name Server boot success. serializeType=JSON
查看mqnamesrv运行的默认的java参数,bin/runserver.sh
4.启动broker服务
查看mqbroker运行的默认的java参数,bin/runbroker.sh
执行nohup sh bin/mqbroker -n 10.56.50.143:9876 &
查看broker日志:tail -f ~/logs/rocketmqlogs/broker.log,成功会打印
main - The broker[edzdeMacBook-Pro-50.local, 192.168.18.133:10911] boot success. serializeType=JSON and name server is localhost:9876
同时在namesrv.log里面会有broker注册的日志,成功会打印
RemotingExecutorThread_1 - new broker registered, 192.168.18.133:10911 HAServer: 192.168.18.133:10912
5.发送消息
在发送消息之前,我们需要告诉客户端namesrv的地址,可以用很多种方式去设置,例如
cd /etc/profile
export NAMESRV_ADDR=10.56.50.143:9876
source /etc/profile
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId=C0A8100B69985E4812488EB8448E03E7, offsetMsgId=C0A8100B00002A9F0000000000057CB0, messageQueue=MessageQueue [topic=TopicTest, brokerName=edzdeMacBook-Pro-50.local, queueId=0], queueOffset=499]
17:07:20.854 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[127.0.0.1:9876] result: true
17:07:20.855 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[192.168.16.11:10911] result: true
6.消费消息
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_13 Receive New Messages: [MessageExt [queueId=2, storeSize=180, queueOffset=232, sysFlag=0, bornTimestamp=1572252955553, bornHost=/192.168.16.11:60677, storeTimestamp=1572252955553, storeHost=/192.168.16.11:10911, msgId=C0A8100B00002A9F0000000000028E2E, commitLogOffset=167470, bodyCRC=1379786659, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Messagcate{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1572253010714, UNIQ_KEY=C0A8100B691B5E4812488EADCFA103A3, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 51, 49], transactionId='null'}]]
7.停止服务
sh bin/mqshutdown broker The mqbroker(36695) is running… Send shutdown request to mqbroker(36695) OK
sh bin/mqshutdown namesrv The mqnamesrv(36664) is running… Send shutdown request to mqnamesrv(36664) OK
8.控制台
下载
git clone https://github.com/apache/rocketmq-externals
修改配置
cd /usr/local/rocketmq/rocketmq-externals/rocketmq-console/src/main/resources
vim application.properties
# 修改如下配置
server.port=8080 // 服务端口号
rocketmq.config.namesrvAddr=10.56.50.143:9876 // 配置服务地址
rocketmq.config.dataPath=/tmp/rocketmq-console/data // mq数据路径,可以自己修改
打包
cd /usr/local/rocketmq/rocketmq-externals/rocketmq-console
mvn clean package -Dmaven.test.skip=true
运行
java -jar rocketmq-console-ng-1.0.0.jar --server.port=8080 --rocketmq.config.namesrvAddr=10.56.50.143:9876
访问
ip:port
9.创建rocketmq数据,同时通过控制台查看
进入/usr/java/rocketmq/bin
创建topic
sh mqadmin -n 10.56.50.143:9876 -c DefaultCluster -t wuleiTopic
TopicConfig [topicName=wuleiTopic, readQueueNums=8, writeQueueNums=8, perm=RW-, topicFilterType=SINGLE_TAG, topicSysFlag=0, order=false]
查看topic,可以知道brokerName
sh mqadmin topicList -n 10.56.50.143:9876
{
"brokerDatas":[
{
"brokerAddrs":{0:"10.56.50.143:10911"
},
"brokerName":"DEFAULT_BROKER",
"cluster":"DefaultCluster"
}
],
"filterServerTable":{},
"queueDatas":[
{
"brokerName":"DEFAULT_BROKER",
"perm":6,
"readQueueNums":8,
"topicSynFlag":0,
"writeQueueNums":8
}
]
}
删除无用的topic
sh mqadmin deleteTopic -n 10.56.50.143:9876 -c DefaultCluster -t test
delete topic [test] from cluster [DefaultCluster] success. delete topic [test] from NameServer success.
发送消息
sh mqadmin sendMsgStatus -b DEFAULT_BROKER -c 1 -n 10.56.50.143:9876
SendResult=SendResult [sendStatus=SEND_OK, msgId=0A38328F71E5339097520396729B0001, offsetMsgId=0A38328F00002A9F0000000000083CBF, messageQueue=MessageQueue [topic=DEFAULT_BROKER, brokerName=DEFAULT_BROKER, queueId=0], queueOffset=1]
创建消费者组
sh mqadmin updateSubGroup -b 10.56.50.143:10911 -g dogConsumeGroup -c DefaultCluster -n 10.56.50.143:9876
create subscription group to 10.56.50.143:10911 success. SubscriptionGroupConfig [groupName=dogConsumeGroup, consumeEnable=true, consumeFromMinEnable=false, consumeBroadcastEnable=false, retryQueueNums=1, retryMaxTimes=16, brokerId=0, whichBrokerWhenConsumeSlowly=1, notifyConsumerIdsChangedEnable=true]
refer
mqadmin broker命令:https://www.jianshu.com/p/4607d931172e
mqadmin 基本命令:https://blog.csdn.net/liujiahan629629/article/details/88563558