Search in sources :

Example 1 with RollbackStats

use of org.apache.rocketmq.common.admin.RollbackStats in project rocketmq-externals by apache.

the class ConsumerServiceImpl method resetOffset.

@Override
@MultiMQAdminCmdMethod
public Map<String, ConsumerGroupRollBackStat> resetOffset(ResetOffsetRequest resetOffsetRequest) {
    Map<String, ConsumerGroupRollBackStat> groupRollbackStats = Maps.newHashMap();
    for (String consumerGroup : resetOffsetRequest.getConsumerGroupList()) {
        try {
            Map<MessageQueue, Long> rollbackStatsMap = mqAdminExt.resetOffsetByTimestamp(resetOffsetRequest.getTopic(), consumerGroup, resetOffsetRequest.getResetTime(), resetOffsetRequest.isForce());
            ConsumerGroupRollBackStat consumerGroupRollBackStat = new ConsumerGroupRollBackStat(true);
            List<RollbackStats> rollbackStatsList = consumerGroupRollBackStat.getRollbackStatsList();
            for (Map.Entry<MessageQueue, Long> rollbackStatsEntty : rollbackStatsMap.entrySet()) {
                RollbackStats rollbackStats = new RollbackStats();
                rollbackStats.setRollbackOffset(rollbackStatsEntty.getValue());
                rollbackStats.setQueueId(rollbackStatsEntty.getKey().getQueueId());
                rollbackStats.setBrokerName(rollbackStatsEntty.getKey().getBrokerName());
                rollbackStatsList.add(rollbackStats);
            }
            groupRollbackStats.put(consumerGroup, consumerGroupRollBackStat);
        } catch (MQClientException e) {
            if (ResponseCode.CONSUMER_NOT_ONLINE == e.getResponseCode()) {
                try {
                    ConsumerGroupRollBackStat consumerGroupRollBackStat = new ConsumerGroupRollBackStat(true);
                    List<RollbackStats> rollbackStatsList = mqAdminExt.resetOffsetByTimestampOld(consumerGroup, resetOffsetRequest.getTopic(), resetOffsetRequest.getResetTime(), true);
                    consumerGroupRollBackStat.setRollbackStatsList(rollbackStatsList);
                    groupRollbackStats.put(consumerGroup, consumerGroupRollBackStat);
                    continue;
                } catch (Exception err) {
                    logger.error("op=resetOffset_which_not_online_error", err);
                }
            } else {
                logger.error("op=resetOffset_error", e);
            }
            groupRollbackStats.put(consumerGroup, new ConsumerGroupRollBackStat(false, e.getMessage()));
        } catch (Exception e) {
            logger.error("op=resetOffset_error", e);
            groupRollbackStats.put(consumerGroup, new ConsumerGroupRollBackStat(false, e.getMessage()));
        }
    }
    return groupRollbackStats;
}
Also used : ConsumerGroupRollBackStat(org.apache.rocketmq.console.model.ConsumerGroupRollBackStat) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) RollbackStats(org.apache.rocketmq.common.admin.RollbackStats) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) List(java.util.List) Map(java.util.Map) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 MQClientException (org.apache.rocketmq.client.exception.MQClientException)1 RollbackStats (org.apache.rocketmq.common.admin.RollbackStats)1 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)1 GroupList (org.apache.rocketmq.common.protocol.body.GroupList)1 MultiMQAdminCmdMethod (org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)1 ConsumerGroupRollBackStat (org.apache.rocketmq.console.model.ConsumerGroupRollBackStat)1