RocketMQ是阿里基于JAVA开源的分布式消息队列中间项目,下载源码进行构建后才能正常使用
一、下载
可视化工具
https://github.com/apache/rocketmq-externals
RocketMQ下载地址,下载解压到rocketmq目录下行构建
https://archive.apache.org/dist/rocketmq/4.6.1/rocketmq-all-4.6.1-source-release.zip
http://rocketmq.apache.org/release_notes/
二、项目构建
> cd rocketmq
# meavn打包
> mvn -Prelease-all -DskipTests clean install -U
# 这里的4.5.x是版本号,可能不同,请注意自己的版本
> cd distribution/target/rocketmq-4.5.x/rocketmq-4.5.x
三、启动 NameServer
> nohup sh bin/mqnamesrv &
# 查看日志,确认是否成功
> tail -f ~/logs/rocketmqlogs/namesrv.log
2019-9-27 21:04:10 INFO NSScheduledThread1 - ----
...
#出现下面信息成功
The Name Server boot success...
```
四、启动 Broker
# 启动Broker
> nohup sh bin/mqbroker -n localhost:9876 &
# 查看日志,确认是否成功
> tail -f ~/logs/rocketmqlogs/broker.log
The broker[%s, 172.30.30.233:10911] boot success...
无法正常启动时,尝试下面命令可看到详细错误信息
sh bin/mqnamesrv
sh bin/mqbroker -n localhost:9876
发送和接收消息
1、生产者发送消息
> export NAMESRV_ADDR=localhost:9876
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
# 出现下面信息成功发送
SendResult [sendStatus=SEND_OK, msgId= ...
2、消费者消费消息
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
# 出现下面信息成功消费
ConsumeMessageThread_%d Receive New Messages: [MessageExt...
五、 关闭服务
# 关闭 broker
> sh bin/mqshutdown broker
The mqbroker(36695) is running...
Send shutdown request to mqbroker(36695) OK
# 关闭 namesrv
> sh bin/mqshutdown namesrv
The mqnamesrv(36664) is running...
Send shutdown request to mqnamesrv(36664) OK
六、注意事项:
1、配置JAVA包构建时下载依赖的国内镜像加速构建,修改Mave构建工具目录中conf/settings.xml的如下
<mirrors>
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>https://mvnrepository.com/</url>
</mirror>
<!-- 增加阿里镜像 -->
<mirror>
<id>pabmaven</id>
<name>pab maven</name> <url>http://maven-repo.pab.com.cn/repository/maven-public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
2、可视化工rocketmq-externals构建时可能会遇到如下异常
Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project rocketmq-console-ng: Failed during checkstyle execution: There is 1 error reported by Checkst
解决方法
找到rocketmq-console目录下的pom.xml中的maven-checkstyle-plugin节点,注掉这个插件
七、Nodejs的实现
https://www.npmjs.com/package/apache-rocketmq
参考:
官方文档 http://rocketmq.apache.org/docs/quick-start/
中文文档 https://rocketmq-1.gitbook.io/rocketmq-connector/quick-start/qian-qi-zhun-bei/dan-ji-huan-jing
RocketMQ中文文档 http://rocketmq.cloud/zh-cn/docs/concept.html