Rocketmq source code analysis and import

Rocketmq source compiler run

download

From github download the source code, more slowly, also from gitee download

Source Directory Structure

name effect
broker broker modules: c p and an end message store logic
client The client api: produce, consumer acceptance and sending end api
common Common Components: Constant base class, the data structure
tools Operation and maintenance tools: command-line tool module
store Memory module: message index, commitlog storage
namesrv Service Management modules: service registration information storage topic
remoting Remote Communication Module: netty + fastjson
logappender Log adaptation module
example Demo Liezi
filtersrv Message filter module
srvutil Auxiliary Module
filter Filter module: message filtering module
distribution Deployment, operation and maintenance related to the zip code
openmessaging Compatible openmessaging distributed messaging module

Compile

Decompression Import idea, modify the configuration file pom.xml, jdk compiled version 1.8
Here Insert Picture Description

# 编译
mvn -Prelease-all -DskipTests clean install -U

Start namesrv

Enter org.apache.rocketmq.namesrv.NamesrvStartup, execute the main method

It throws an error, because there is no set path to the configuration file ROCKETMQ_HOME

Please set the ROCKETMQ_HOME variable in your environment to match the lo
cation of the RocketMQ installation  

Here Insert Picture Description

Code location org.apache.rocketmq.namesrv.NamesrvStartup # createNamesrvController, modify the source, increase configuration rocketHome

RocketHome may be provided by modifying the boot parameters, in the configuration parameters for the VM run configurators idea of

-Drocketmq.home.dir = D: \ code \ java_yuanma \ rocketmq \ distribution

It also needs to be set user.home, specify the log file path

-Duser.home=D:\code\java_yuanma\rocketmq\user.home

还需要配置namesrv的ip和port

Here Insert Picture Description

然后运行NamesrvStartup#main启动namesrv

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-0ncNb2iI-1578200015945) (F: / 2019 /% E4% B9% A6 /% E7% AC% 94% E8% AE% B0% E6% 95% B4% E7% 90% 862 / rocketmq / idea% E8% B0% 83% E8% AF% 95rocketmq% E6% BA% 90% E7% A0% 81.assets / image- 20191113161603998.png)]

控制台出现上图结果,启动成功

启动broker

进入org.apache.rocketmq.broker.BrokerStartup,可以执行main方法,同样需要先配置rocketHome

在org.apache.rocketmq.broker.BrokerStartup#createBrokerController中修改源码,增加rocketHome的配置

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-keDbDiZZ-1578200015946) (F: / 2019 /% E4% B9% A6 /% E7% AC% 94% E8% AE% B0% E6% 95% B4% E7% 90% 862 / rocketmq / idea% E8% B0% 83% E8% AF% 95rocketmq% E6% BA% 90% E7% A0% 81.assets / image- 20191113161934004.png)]

也可以通过修改启动参数设置rocketHome, 在idea的run configurators中配置 VM参数为

-Drocketmq.home.dir=D:\code\java_yuanma\rocketmq\distribution

同时还需要设置user.home,指定日志文件路径

-Duser.home=D:\code\java_yuanma\rocketmq\user.home

还需要配置程序参数

‐n 127.0.0.0:9876 -c D:\code\java_yuanma\rocketmq\distribution\conf\broker.conf

[Pictures of foreign chains dumping fails, the source station may have security chain mechanism, it is recommended to save the picture down uploaded directly (img-4q0fckkH-1578200015946) (F: / 2019 /% E4% B9% A6 /% E7% AC% 94% E8% AE% B0% E6% 95% B4% E7% 90% 862 / rocketmq / idea% E8% B0% 83% E8% AF% 95rocketmq% E6% BA% 90% E7% A0% 81.assets / image- 20191113162243329.png)]

然后运行BrokerStartup#main启动broker

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ohWxpbgo-1578200015947)(F:/2019/%E4%B9%A6/%E7%AC%94%E8%AE%B0%E6%95%B4%E7%90%862/rocketmq/idea%E8%B0%83%E8%AF%95rocketmq%E6%BA%90%E7%A0%81.assets/image-20191113162341378.png)]控制台出现上图结果,启动成功

如果出现以下情况,ip不对,是因为多网卡的问题

在这里插入图片描述

这时需要修改D:\code\java_yuanma\rocketmq\distribution\conf\broker.conf 此配置文件

增加brokerIP1 = 127.0.0.1

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MOBRa8ul-1578200015948)(F:/2019/%E4%B9%A6/%E7%AC%94%E8%AE%B0%E6%95%B4%E7%90%862/rocketmq/idea%E8%B0%83%E8%AF%95rocketmq%E6%BA%90%E7%A0%81.assets/image-20191113162710590.png)]

测试

启动Producer发消息,成功

如果出现No Topic Route Info 错误:

broker.conf 中增加配置

autoCreateTopicEnable = true
namesrvAddr = 127.0.0.1:9876
发布了241 篇原创文章 · 获赞 305 · 访问量 54万+

Guess you like

Origin blog.csdn.net/HarderXin/article/details/103842062