52.源代码解读-RocketMQ消息写入机制
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,一. 前言RocketMQ采用内存和磁盘存储来存储消息。那现在来分析一下消息存储的流程二. 代码流程在Broker启动的时候会拉起相关服务流程如下:流程图引用网址http://blog.csdn.ne
千家信息网最后更新 2026年11月02日52.源代码解读-RocketMQ消息写入机制
一. 前言
RocketMQ采用内存和磁盘存储来存储消息。那现在来分析一下消息存储的流程
二. 代码流程
在Broker启动的时候会拉起相关服务
流程如下:

流程图引用网址
http://blog.csdn.net/akfly/article/details/53447000
三. 代码流程
由于是Broker来存储消息,那么消息入口的代码应该是在Broker里面,而Broker的入口是BrokerStartup,以及重要的BrokerController。
具体流程可以参考Broker启动源代码分析。
Broker启动流程
以发送消息为例
1. Broker启动注册发送消息处理器
Broker启动的时候,会注册一个SendMessageProcesser来响应netty的发送消息请求,如下:
public void registerProcessor() { /** * SendMessageProcessor */ SendMessageProcessor sendProcessor = new SendMessageProcessor(this); sendProcessor.registerSendMessageHook(sendMessageHookList); sendProcessor.registerConsumeMessageHook(consumeMessageHookList); this.remotingServer.registerProcessor(RequestCode.SEND_MESSAGE, sendProcessor, this.sendMessageExecutor); this.remotingServer.registerProcessor(RequestCode.SEND_MESSAGE_V2, sendProcessor, this.sendMessageExecutor); this.remotingServer.registerProcessor(RequestCode.SEND_BATCH_MESSAGE, sendProcessor, this.sendMessageExecutor); this.remotingServer.registerProcessor(RequestCode.CONSUMER_SEND_MSG_BACK, sendProcessor, this.sendMessageExecutor); this.fastRemotingServer.registerProcessor(RequestCode.SEND_MESSAGE, sendProcessor, this.sendMessageExecutor); this.fastRemotingServer.registerProcessor(RequestCode.SEND_MESSAGE_V2, sendProcessor, this.sendMessageExecutor); this.fastRemotingServer.registerProcessor(RequestCode.SEND_BATCH_MESSAGE, sendProcessor, this.sendMessageExecutor); this.fastRemotingServer.registerProcessor(RequestCode.CONSUMER_SEND_MSG_BACK, sendProcessor, this.sendMessageExecutor);}2. 消息处理器处理发送者发送过来的消息
public class SendMessageProcessor extends AbstractSendMessageProcessor implements NettyRequestProcessor { @Override public RemotingCommand proce***equest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext; ... switch (request.getCode()) { response = this.sendMessage(ctx, request, mqtraceContext, requestHeader); } }} 继续看sendMessage..
private RemotingCommand sendMessage(final ChannelHandlerContext ctx, ... PutMessageResult putMessageResult = this.brokerController.getMessageStore().putMessage(msgInner);} 调用MessageStore.putMessage(msgInner)
消息
流程
存储
代码
处理
入口
处理器
时候
分析
源代码
重要
内存
前言
发送者
是在
流程图
磁盘
网址
参考
服务
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
中关村互联网 科技集团
蓝思科技飞鸽互联网
圆梦互联网科技
互联网科技开发公司
互联网科技公司官网
互联网科技论文
科技创新互联网企业
无线互联网科技
互联网科技咨询
上海电发互联网科技有限公司
全球顶尖互联网科技公司
湖北码尼互联网科技有限公司电话
知域互联网科技有限公司大骗子
深圳市优智互联网科技有限公司
乌苏新华互联网科技做什么的
滨湖区互联网智能科技产品有哪些
工业互联网科技创业
陕西九四连强互联网科技有限公司
恒生互联网科技趋势
宁波允成互联网科技有限公司
互联网科技有限公司经营范围
美国互联网科技
未来的互联网科技
互联网科技网站
顶级互联网科技成果有哪些
苏州五指互联网络科技有限
互联网5g黑科技有哪些
广州千川互联网科技有限公司
郑州欣桑互联网科技有限公司
国产互联网科技公司