1.1 环境搭建
依赖工具
- JDK :1.8+
- Maven
- IntelliJ IDEA
1.1.1 源码拉取
从官方仓库 https://github.com/apache/rocketmq clone 或者download 源码。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fYmjiFpB-1652681429918)(img/源码1.png)]
源码目录结构:
-
broker: broker 模块(broke 启动进程) -
client :消息客户端,包含消息生产者、消息消费者相关类 -
common :公共包 -
dev :开发者信息(非源代码) -
distribution :部署实例文件夹(非源代码) -
example: RocketMQ 例代码 -
filter :消息过滤相关基础类 -
filtersrv:消息过滤服务器实现相关类(Filter启动进程) -
logappender:日志实现相关类 -
namesrv:NameServer实现相关类(NameServer启动进程) -
openmessageing:消息开放标准 -
remoting:远程通信模块,给予Netty -
srcutil:服务工具类 -
store:消息存储实现相关类 -
style:checkstyle相关实现 -
test:测试相关类 -
tools:工具类,监控命令相关实现类
1.1.2 导入IDEA
执行安装
mvn clean install -Dmaven.test.skip=true
1.1.3 调试
创建conf 配置文件夹,从distribution 拷贝broker.conf 和logback_broker.xml 和logback_namesrv.xml
1)启动NameServer
The Name Server boot success. serializeType=JSON
2)启动Broker
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable=true
namesrvAddr=192.168.1.8:9876
brokerIP1=192.168.1.8
# 存储路径
storePathRootDir=/Users/qinfuxiang/RocketMQ/data/rocketmq/dataDir
# commitLog路径
storePathCommitLog=/Users/qinfuxiang/RocketMQ/data/rocketmq/dataDir/commitlog
- 创建数据文件夹
dataDir - 启动
BrokerStartup ,配置broker.conf 和ROCKETMQ_HOME
-c /Users/qinfuxiang/IdeaProjects/rocketmq/conf/broker.conf
ROCKETMQ_HOME=/Users/qinfuxiang/IdeaProjects/rocketmq
3)发送消息
- 进入example模块的
org.apache.rocketmq.example.quickstart - 指定Namesrv地址
DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
producer.setNamesrvAddr("192.168.1.8:9876");
4)消费消息
- 进入example模块的
org.apache.rocketmq.example.quickstart - 指定Namesrv地址
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_4");
consumer.setNamesrvAddr("192.168.1.8:9876");
2.1 rocketmq dashboard搭建
https://github.com/apache/rocketmq-dashboard clone
注释掉pom中两个插件
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
启动既可以访问:http://localhost:8080/#/
|