0.依赖工具
- JDK :1.8+
- Maven
- IntelliJ IDEA
1.源码下载
Rocketmq源码下载网址
2.源码目录结构
3.将源码导入IDEA; 4.执行
clean install -Dmaven.test.skip=true
5.调试 在项目根目录下,新建一个conf文件夹; 6.将distribution目录下,红方框圈起来的三个文件拷贝到conf文件夹下; 7.启动NameSrv和Broker;
1)启动NameServer
- 展开namesrv模块,右键NamesrvStartup.java
- 配置ROCKETMQ_HOME
- 重新启动
控制台打印结果
The Name Server boot success. serializeType=JSON
2)启动Broker
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
namesrvAddr=127.0.0.1:9876
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable=true
storePathRootDir=C:\\RocketMQ\\data\\rocketmq\\dataDir
storePathCommitLog=C:\\RocketMQ\\data\\rocketmq\\dataDir\\commitlog
storePathConsumeQueue=C:\\RocketMQ\\data\\rocketmq\\dataDir\\consumequeue
storePathIndex=C:\\RocketMQ\\data\\rocketmq\\dataDir\\index
storeCheckpoint=C:\\RocketMQ\\data\\rocketmq\\dataDir\\checkpoint
abortFile=C:\\RocketMQ\\data\\rocketmq\\dataDir\\abort
替换后的broker.conf内容如下:
- 启动Broker
点击运行main函数;出现和NameSrv同样的问题,这时,需要配置RocketMQ_HOME; 使用同样方法配置BrokerStartup; 同时,配置项目参数:
-c broker配置文件路径
例如:
-c C:\codes\rocketmq-master\rocketmq-master\conf\broker.conf
Apply -> OK;即可。
- 再次,打开BrokerStartup,运行main函数;
8.生产消息和消费消息 1.打开Producer; 2.配置Producer,并启动生产者
DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
producer.setNamesrvAddr("127.0.0.1:9876");
如下图所示: 3.配置Consumer,并启动消费者
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_4");
consumer.setNamesrvAddr("127.0.0.1:9876");
如下图所示:
|