}
private RemotingCommand updateConsumerOffset(ChannelHandlerContext ctx, RemotingCommand request)
throws RemotingCommandException {
final RemotingCommand response =
RemotingCommand.createResponseCommand(UpdateConsumerOffsetResponseHeader.class);
final UpdateConsumerOffsetResponseHeader responseHeader =
(UpdateConsumerOffsetResponseHeader) response.readCustomHeader();
final UpdateConsumerOffsetRequestHeader requestHeader =
(UpdateConsumerOffsetRequestHeader) request
.decodeCommandCustomHeader(UpdateConsumerOffsetRequestHeader.class);
// 消息轨迹:记录已经消费成功并提交 offset 的消息记录
if (this.hasConsumeMessageHook()) {
// 执行hook
ConsumeMessageContext context = new ConsumeMessageContext();
context.setConsumerGroup(requestHeader.getConsumerGroup());
context.setTopic(requestHeader.getTopic());
context.setClientHost(RemotingHelper.parseChannelRemoteAddr(ctx.channel()));
context.setSuccess(true);
context.setStatus(ConsumeConcurrentlyStatus.CONSUME_SUCCESS.toString());
final SocketAddress storeHost =
new InetSocketAddress(brokerController.getBrokerConfig().getBrokerIP1(), brokerController
.getNettyServerConfig().getListenPort());
long preOffset =
this.brokerController.getConsumerOffsetManager().queryOffset(
requestHeader.getConsumerGroup(), requestHeader.getTopic(),
requestHeader.getQueueId());
Map<String, Long> messageIds =
this.brokerController.getMessageStore().getMessageIds(requestHeader.getTopic(),
requestHeader.getQueueId(), preOffset, requestHeader.getCommitOffset(), storeHost);
context.setMessageIds(messageIds);
this.executeConsumeMessageHookAfter(context);
}
this.brokerController.getConsumerOffsetManager().commitOffset(requestHeader.getConsumerGroup(),
requestHeader.getTopic(), requestHeader.getQueueId(), requestHeader.getCommitOffset());
response.setCode(ResponseCode.SUCCESS);
response.setRemark(null);
return response;
}