获取源代码
https://github.com/apache/rocketmq
在idea中打开项目,执行命令
git clone https://github.com/apache/rocketmq
mvn clean install -DskipTests
运行代码步骤
1、启动NameServer
2、启动Broker
3、运行Consumer
4、运行Producer
源码目录结构
一、准备环境
新建rocketmq的运行目录,deploy_mq
并在deploy_mq文件夹下新建三个文件夹:conf,logs,store
将源码文件夹下
- distribution/conf/broker.conf
- distribution/conf/logback_broker.xml
- distribution/conf/logback_namesrv.xml
复制到deploy_mq/conf 目录下
修改 broker.conf ,配置如下
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 如果在执行 example 程序的时候,报错No Topic Route Info,解决就是加一个配置
# autoCreateTopicEnable = true
# 存储路径
storePathRootDir=/Users/xxx/JavaProject/lxw_rocketmq/deploy_mq/store
# commitLog 路径
storePathCommitLog=/Users/xxx/JavaProject/lxw_rocketmq/deploy_mq/store/commitlog
# 消费队列存储路径
storePathConsumeQueue=/Users/xxx/JavaProject/lxw_rocketmq/deploy_mq/store/consumequeue
# 消息索引存储路径
storePathIndex=/Users/xxx/JavaProject/lxw_rocketmq/deploy_mq/store/index
# checkePoint 文件存储路径
storeCheckpoint=/Users/xxx/JavaProject/lxw_rocketmq/deploy_mq/store/checkpoint
# abort 文件存储路径
abortFile=/Users/xxx/JavaProject/lxw_rocketmq/deploy_mq/store/abort
二、启动NameServer
找到 rocketmq/namesrv/NamesrvStartup.java,执行main函数即可。
执行之前先修改一下配置文件,增加 Environment variables
ROCKETMQ_HOME=/Users/xxx/JavaProject/lxw_rocketmq/deploy_mq
三、启动Broker
找到 rocketmq/broker/BrokerStartup.java,执行main函数即可。
执行之前先修改 Environment variables
ROCKETMQ_HOME=/Users/xxx/JavaProject/lxw_rocketmq/deploy_mq
还要修改 Program arguments
-c /Users/bytedance/JavaProject/lxw_rocketmq/deploy_mq/conf/broker.conf
-n 127.0.0.1:9876
autoCreateTopicEnable=true
四、启动 Consumer
找到 example/quickstart/Consumer.java ,修改 nameserver 的地址。
consumer.setNamesrvAddr("127.0.0.1:9876");
五、启动 Producer
找到 example/quickstart/Producer.java ,修改 nameserver 的地址。
producer.setNamesrvAddr("127.0.0.1:9876");
六、参考
- https://my.oschina.net/u/4366528/blog/3485627