ConsumeStats consumeStats =
this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, 3000);
// 根据 topic 过滤不需要的 mq
for (Map.Entry<MessageQueue, OffsetWrapper> entry : consumeStats.getOffsetTable().entrySet()) {
MessageQueue queue = entry.getKey();
OffsetWrapper offsetWrapper = entry.getValue();
if (topic.equals(queue.getTopic())) {
// 根据 timestamp 查找对应的offset
long offset =
this.mqClientInstance.getMQClientAPIImpl().searchOffset(addr, topic,
queue.getQueueId(), timestamp, 3000);
// 构建按时间回溯消费进度
RollbackStats rollbackStats = new RollbackStats();
rollbackStats.setBrokerName(bd.getBrokerName());
rollbackStats.setQueueId(queue.getQueueId());
rollbackStats.setBrokerOffset(offsetWrapper.getBrokerOffset());
rollbackStats.setConsumerOffset(offsetWrapper.getConsumerOffset());
rollbackStats.setTimestampOffset(offset);
rollbackStats.setRollbackOffset(offsetWrapper.getConsumerOffset());
// 更新 offset
if (force || offset <= offsetWrapper.getConsumerOffset()) {
rollbackStats.setRollbackOffset(offset);
UpdateConsumerOffsetRequestHeader requestHeader =
new UpdateConsumerOffsetRequestHeader();
requestHeader.setConsumerGroup(consumerGroup);
requestHeader.setTopic(topic);
requestHeader.setQueueId(queue.getQueueId());
requestHeader.setCommitOffset(offset);
this.mqClientInstance.getMQClientAPIImpl().updateConsumerOffset(addr,
requestHeader, 3000);
}
rollbackStatsList.add(rollbackStats);