1.获得RocketMQ源码
1.1在Github上寻找RocketMQ项目,操作如图1
1.2拷贝git链接,后面使用IDEA下载,如图2
1.3使用IDEA如图3操作,把该项目clone到本地:
1.4在IDEA自动的命令窗口,输入mvn clean install -Dmaven.test.skip=true,进行编译和下载所需要的依赖
2.调试源码
(2.1)启动NameServer
step1:打开namesrv模块,找到namesrvStartup.java文件,右键Debug,然后在Debug中配置Enviroment variables: ROCKETMQ_HOME=F:\JAVA_EE_code\rocketmq。如图图5
step2:在RocketMQ运行主目录创建conf、logs、store三个文件夹。
step3:在distribution部署目录中将broker.conf,logback_broker.xml,logback_namesrv.xml三个文件复制到conf目录下。logback_namesrv.xml修改日志文件的位置,broker.conf文件的容如下:
''' java
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
#nameServer地址,分号分割
namesrvAddr = 127.0.0.1:9876
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
#存储路径
storePathRootDir = F:\\JAVA EE_code\\rocketmq\\store
#commitLog 存储路径
storePathCommitLog=F:\\JAVA EE_code\\rocketmq\\store\\commitLog
#消费队列存储路径
storePathConsumeQueue=F:\\JAVA EE_code\\rocketmq\\store\\consumequeue
#消息索引存储路径
storePathIndex=F:\\JAVA EE_code\\rocketmq\\rocketmq\\store\\index
#checkpoint 文件存储路径
storeCheckPoint=F:\\JAVA EE_code\\rocketmq\\store\\checkpoint
#abort 文件存储路径
abortFile=F:\\JAVA EE_code\\rocketmq\\store\\abort
'''