Spring Cloud Alibaba学习笔记(8) - RocketMQ安装与RocketMQ控制台

匿名 (未验证) 提交于 2019-12-03 00:15:02
  1. 64位操作系统,推荐使用Linux、Unix、MacOS
  2. 64λ JDK1.8+
  3. Maven 3.2.x
  4. 适用于Broker服务器的4g +可用磁盘

从Apache RocketMQ的官网【http://rocketmq.apache.org/ 】可以进入RocketMQ的下载地址,目前最新的版本为4.5.2【http://rocketmq.apache.org/release_notes/release-notes-4.5.2/ 】,下载Binary文件即可

  • 解压缩
    unzip rocketmq-all-4.5.2-bin-release.zip
  • 切换目录
    cd rocketmq-all-4.5.2-bin-release
  • 启动Name Server
    nohup sh bin/mqnamesrv &
    验证是否启动成功
    tail -f ~/logs/rocketmqlogs/namesrv.log
    如果启动成功,可以看见如下日志:
    2019-10-24 16:20:48 INFO FileWatchService - FileWatchService service started
    2019-10-24 16:20:48 INFO main - The Name Server boot success. serializeType=JSON

  • 启动Broker
    nohup sh bin/mqbroker -n localhost:9876 &
    验证是否启动成功
    tail -f ~/logs/rocketmqlogs/broker.log
    如果启动成功,可以看见如下日志:
    2019-10-25 10:46:16 INFO brokerOutApi_thread_2 - register broker[0]to name server localhost:9876 OK

PS:默认启动Broker要求的内存非常的高,往往会因为内存不足的原因导致broker启动失败:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)
这时,需要调整bin文件夹中的 runbroker.sh文件,调整,修改:
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"

执行如下命令

export NAMESRV_ADDR=localhost:9876 sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer

可以看见如下输出
SendResult [sendStatus=SEND_OK, msgId=C0A81F650E80511D50C07DE6317903E7, offsetMsgId=C0A81F6500002A9F000000000002BDFE, messageQueue=MessageQueue [topic=TopicTest, brokerName=fanxuan-TM1604, queueId=3], queueOffset=249]

执行如下命令

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

可以看见如下输出
ConsumeMessageThread_20 Receive New Messages: [MessageExt [queueId=1, storeSize=180, queueOffset=174, sysFlag=0, bornTimestamp=1571971437603, bornHost=/192.168.31.101:49768, storeTimestamp=1571971437604, storeHost=/192.168.31.101:10911, msgId=C0A81F6500002A9F000000000001E9A6, commitLogOffset=125350, bodyCRC=1257100577, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1571971518424, UNIQ_KEY=C0A81F650E80511D50C07DE6302302B9, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 54, 57, 55], transactionId='null'}]]

停止 broker:sh bin/mqshutdown broker
停止 nameserver:sh bin/mqshutdown namesrv

git clone https://github.com/apache/rocketmq-externals.git

修改rocketmq-externals/rocketmq-console/src/main/resources/application.properties文件:

  • server.port:默认端口8080,容易与其他端口冲突,建议修改
  • rocketmq.config.namesrvAddr:name server地址,localhost:9876

修改rocketmq-externals/rocketmq-console/pom.xml文件:
rocketmq.version改为你自己的版本
PS:建议使用4.5.1,4.5.2版本会导致MQAdminExtImpl报错

找到org.apache.rocketmq.console.service.impl.MessageServiceImpl文件,修改queryMessageByTopic方法中的
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP, null);
为:
RPCHook rpcHook = null;
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP, rpcHook);
另外需要引入包:
import org.apache.rocketmq.remoting.RPCHook;

打开终端,切换到rocketmq-console目录下,重新构建项目:
mvn clean package -DskipTests

编译成功:
[INFO] --- maven-source-plugin:3.0.1:jar (attach-sources) @ rocketmq-console-ng ---
[INFO] Building jar: /home/fanxuan/Server/RocketMQ/rocketmq-externals/rocketmq-console/target/rocketmq-console-ng-1.0.1-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.404 s
[INFO] Finished at: 2019-10-25T12:35:19+08:00
[INFO] ------------------------------------------------------------------------

target文件夹中找到新编译好的包,启动:
java -jar rocketmq-console-ng-1.0.1.jar

启动成功之后,浏览器,输入localhost:8888【修改配置中修改的server.port值】

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!