else {
offsetTable.put(mq, consumerOffset);
}
}
ResetOffsetRequestHeader requestHeader = new ResetOffsetRequestHeader();
requestHeader.setTopic(topic);
requestHeader.setGroup(group);
requestHeader.setTimestamp(timeStamp);
RemotingCommand request =
RemotingCommand.createRequestCommand(RequestCode.RESET_CONSUMER_CLIENT_OFFSET, requestHeader);
ResetOffsetBody body = new ResetOffsetBody();
body.setOffsetTable(offsetTable);
request.setBody(body.encode());
ConsumerGroupInfo consumerGroupInfo =
this.brokerController.getConsumerManager().getConsumerGroupInfo(group);
// Consumer在线
if (consumerGroupInfo != null && !consumerGroupInfo.getAllChannel().isEmpty()) {
ConcurrentHashMap<Channel, ClientChannelInfo> channelInfoTable =
consumerGroupInfo.getChannelInfoTable();
for (Channel channel : channelInfoTable.keySet()) {
int version = channelInfoTable.get(channel).getVersion();
if (version >= MQVersion.Version.V3_0_7_SNAPSHOT.ordinal()) {
try {
this.brokerController.getRemotingServer().invokeOneway(channel, request, 5000);
log.info("[reset-offset] reset offset success. topic={}, group={}, clientId={}",
new Object[] { topic, group, channelInfoTable.get(channel).getClientId() });
}
catch (Exception e) {
log.error("[reset-offset] reset offset exception. topic={}, group={}",
new Object[] { topic, group }, e);
}
}
else {
// 如果有一个客户端是不支持该功能的,则直接返回错误,需要应用方升级。
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark("the client does not support this feature. version="
+ MQVersion.getVersionDesc(version));
log.warn("[reset-offset] the client does not support this feature. version={}",
RemotingHelper.parseChannelRemoteAddr(channel), MQVersion.getVersionDesc(version));
return response;
}
}
}
// Consumer不在线
else {
String errorInfo =
String.format(
"Consumer not online, so can not reset offset, Group: %s Topic: %s Timestamp: %d",//
requestHeader.getGroup(), //
requestHeader.getTopic(), //
requestHeader.getTimestamp());
log.error(errorInfo);
response.setCode(ResponseCode.CONSUMER_NOT_ONLINE);
response.setRemark(errorInfo);
return response;
}