Said ahead
Message Pull Processor
Source code analysis
Enter this method and find the mapping file according to offset, as described above at org. apache. rocketmq. store. MappedFileQueue # find MappedFileByOffset (long, boolean).
Return to this method and find the next mapping file based on offset, org.apache.rocketmq.store.CommitLog#rollNextFile
public long rollNextFile(final long offset) { int mappedFileSize = this.defaultMessageStore.getMessageStoreConfig().getMapedFileSizeCommitLog(); return offset + mappedFileSize - offset % mappedFileSize; }
Back to this method, the hook method that executes message consumption is org.apache.rocketmq.broker.processor.PullMessageProcessor#executeConsumeMessageHookBefore consuming the message
public void executeConsumeMessageHookBefore(final ConsumeMessageContext context) { if (hasConsumeMessageHook()) { for (ConsumeMessageHook hook : this.consumeMessageHookList) { try { // Users can implement their own hook method before consumption hook.consumeMessageBefore(context); } catch (Throwable e) { } } } }
Back to this method, pause the message pull service, org. apache. rocketmq. broker. longpolling. PullRequestHoldService # suspend PullRequest
public void suspendPullRequest(final String topic, final int queueId, final PullRequest pullRequest) { String key = this.buildKey(topic, queueId); ManyPullRequest mpr = this.pullRequestTable.get(key); if (null == mpr) { mpr = new ManyPullRequest(); ManyPullRequest prev = this.pullRequestTable.putIfAbsent(key, mpr); if (prev != null) { mpr = prev; } } mpr.addPullRequest(pullRequest); }
Go back to this method and submit offset, org.apache.rocketmq.broker.offset.ConsumerOffsetManager#commitOffset(java.lang.String, java.lang.String, java.lang.String, int, long)
public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset) { // topic@group String key = topic + TOPIC_GROUP_SEPARATOR + group; // => this.commitOffset(clientHost, key, queueId, offset); }
Enter this method, org.apache.rocketmq.broker.offset.ConsumerOffsetManager#commitOffset(java.lang.String, java.lang.String, int, long)
private void commitOffset(final String clientHost, final String key, final int queueId, final long offset) { ConcurrentMap<Integer, Long> map = this.offsetTable.get(key); if (null == map) { map = new ConcurrentHashMap<Integer, Long>(32); map.put(queueId, offset); this.offsetTable.put(key, map); } else { Long storeOffset = map.put(queueId, offset); if (storeOffset != null && offset < storeOffset) { log.warn("[NOTIFYME]update consumer offset less than store. clientHost={}, key={}, queueId={}, requestOffset={}, storeOffset={}", clientHost, key, queueId, offset, storeOffset); } } }
Back to this method, org. apache. rocketmq. broker. processor. PullMessageProcessor processRequest (io. netty. channel. Channel, org. apache. rocketmq. remoting. protocol. RemotingCommand, boolean) ends.
Said at the end
This analysis only represents personal views, for reference only.
Nail Technology Group