初识消息存储

消息存储实现类org.apache.rocketmq.store.DefaultMessageStore是存储模块里面最重要的一个类,包含了很多对存储文件进行操作的API,其他模块对消息实体的操作都是通过DefaultMessageStore进行的,如图4-7所示。

image 2025 01 17 17 30 38 302
Figure 1. 图4-7 DefaultMessageStore类图

下面逐一介绍DefaultMessageStore的核心属性。 1)MessageStoreConfig messageStoreConfig:消息存储配置属性。 2)CommitLog commitLog:CommitLog文件的存储实现类。 3)ConcurrentMap consumeQueueTable:消息队列存储缓存表,按消息主题分组。 4)FlushConsumeQueueService flushConsumeQueueService:ConsumeQueue文件刷盘线程。 5)CleanCommitLogService cleanCommitLogService:清除CommitLog文件服务。 6)CleanConsumeQueueService cleanConsumeQueueService:清除ConsumeQueue文件服务。 7)IndexService indexService:Index文件实现类。 8)AllocateMappedFileService allocateMappedFileService:MappedFile分配服务。 9)ReputMessageService reputMessageService:CommitLog消息分发,根据CommitLog文件构建ConsumeQueue、Index文件。 10)HAService haService:存储高可用机制。 11)TransientStorePool transientStorePool:消息堆内存缓存。 12)MessageArrivingListener messageArrivingListener:在消息拉取长轮询模式下的消息达到监听器。 13)BrokerConfig brokerConfig:Broker配置属性。 14)StoreCheckpoint storeCheckpoint:文件刷盘检测点。 15)LinkedList dispatcherList:CommitLog文件转发请求。