Search in sources :

Example 1 with MultiMQAdminCmdMethod

use of org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod in project rocketmq-externals by apache.

the class ConsumerServiceImpl method queryGroupList.

@Override
@MultiMQAdminCmdMethod
public List<GroupConsumeInfo> queryGroupList() {
    Set<String> consumerGroupSet = Sets.newHashSet();
    try {
        ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        for (BrokerData brokerData : clusterInfo.getBrokerAddrTable().values()) {
            SubscriptionGroupWrapper subscriptionGroupWrapper = mqAdminExt.getAllSubscriptionGroup(brokerData.selectBrokerAddr(), 3000L);
            consumerGroupSet.addAll(subscriptionGroupWrapper.getSubscriptionGroupTable().keySet());
        }
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
    List<GroupConsumeInfo> groupConsumeInfoList = Lists.newArrayList();
    for (String consumerGroup : consumerGroupSet) {
        groupConsumeInfoList.add(queryGroup(consumerGroup));
    }
    Collections.sort(groupConsumeInfoList);
    return groupConsumeInfoList;
}
Also used : GroupConsumeInfo(org.apache.rocketmq.console.model.GroupConsumeInfo) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 2 with MultiMQAdminCmdMethod

use of org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod 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)

Example 3 with MultiMQAdminCmdMethod

use of org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod in project rocketmq-externals by apache.

the class ConsumerServiceImpl method examineSubscriptionGroupConfig.

@Override
@MultiMQAdminCmdMethod
public List<ConsumerConfigInfo> examineSubscriptionGroupConfig(String group) {
    List<ConsumerConfigInfo> consumerConfigInfoList = Lists.newArrayList();
    try {
        ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        for (String brokerName : clusterInfo.getBrokerAddrTable().keySet()) {
            // foreach brokerName
            String brokerAddress = clusterInfo.getBrokerAddrTable().get(brokerName).selectBrokerAddr();
            SubscriptionGroupConfig subscriptionGroupConfig = mqAdminExt.examineSubscriptionGroupConfig(brokerAddress, group);
            if (subscriptionGroupConfig == null) {
                continue;
            }
            consumerConfigInfoList.add(new ConsumerConfigInfo(Lists.newArrayList(brokerName), subscriptionGroupConfig));
        }
    } catch (Exception e) {
        throw propagate(e);
    }
    return consumerConfigInfoList;
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) ConsumerConfigInfo(org.apache.rocketmq.console.model.request.ConsumerConfigInfo) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 4 with MultiMQAdminCmdMethod

use of org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod in project rocketmq-externals by apache.

the class ConsumerServiceImpl method queryConsumeStatsList.

@Override
@MultiMQAdminCmdMethod
public List<TopicConsumerInfo> queryConsumeStatsList(final String topic, String groupName) {
    ConsumeStats consumeStats = null;
    try {
        consumeStats = mqAdminExt.examineConsumeStats(groupName, topic);
    } catch (Exception e) {
        throw propagate(e);
    }
    List<MessageQueue> mqList = Lists.newArrayList(Iterables.filter(consumeStats.getOffsetTable().keySet(), new Predicate<MessageQueue>() {

        @Override
        public boolean apply(MessageQueue o) {
            return StringUtils.isBlank(topic) || o.getTopic().equals(topic);
        }
    }));
    Collections.sort(mqList);
    List<TopicConsumerInfo> topicConsumerInfoList = Lists.newArrayList();
    TopicConsumerInfo nowTopicConsumerInfo = null;
    Map<MessageQueue, String> messageQueueClientMap = getClientConnection(groupName);
    for (MessageQueue mq : mqList) {
        if (nowTopicConsumerInfo == null || (!StringUtils.equals(mq.getTopic(), nowTopicConsumerInfo.getTopic()))) {
            nowTopicConsumerInfo = new TopicConsumerInfo(mq.getTopic());
            topicConsumerInfoList.add(nowTopicConsumerInfo);
        }
        QueueStatInfo queueStatInfo = QueueStatInfo.fromOffsetTableEntry(mq, consumeStats.getOffsetTable().get(mq));
        queueStatInfo.setClientInfo(messageQueueClientMap.get(mq));
        nowTopicConsumerInfo.appendQueueStatInfo(queueStatInfo);
    }
    return topicConsumerInfoList;
}
Also used : QueueStatInfo(org.apache.rocketmq.console.model.QueueStatInfo) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) TopicConsumerInfo(org.apache.rocketmq.console.model.TopicConsumerInfo) MQClientException(org.apache.rocketmq.client.exception.MQClientException) Predicate(com.google.common.base.Predicate) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 5 with MultiMQAdminCmdMethod

use of org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod in project rocketmq-externals by apache.

the class ConsumerServiceImpl method queryGroup.

@Override
@MultiMQAdminCmdMethod
public GroupConsumeInfo queryGroup(String consumerGroup) {
    GroupConsumeInfo groupConsumeInfo = new GroupConsumeInfo();
    try {
        ConsumeStats consumeStats = null;
        try {
            consumeStats = mqAdminExt.examineConsumeStats(consumerGroup);
        } catch (Exception e) {
            logger.warn("examineConsumeStats exception, " + consumerGroup, e);
        }
        ConsumerConnection consumerConnection = null;
        try {
            consumerConnection = mqAdminExt.examineConsumerConnectionInfo(consumerGroup);
        } catch (Exception e) {
            logger.warn("examineConsumerConnectionInfo exception, " + consumerGroup, e);
        }
        groupConsumeInfo.setGroup(consumerGroup);
        if (consumeStats != null) {
            groupConsumeInfo.setConsumeTps((int) consumeStats.getConsumeTps());
            groupConsumeInfo.setDiffTotal(consumeStats.computeTotalDiff());
        }
        if (consumerConnection != null) {
            groupConsumeInfo.setCount(consumerConnection.getConnectionSet().size());
            groupConsumeInfo.setMessageModel(consumerConnection.getMessageModel());
            groupConsumeInfo.setConsumeType(consumerConnection.getConsumeType());
            groupConsumeInfo.setVersion(MQVersion.getVersionDesc(consumerConnection.computeMinVersion()));
        }
    } catch (Exception e) {
        logger.warn("examineConsumeStats or examineConsumerConnectionInfo exception, " + consumerGroup, e);
    }
    return groupConsumeInfo;
}
Also used : GroupConsumeInfo(org.apache.rocketmq.console.model.GroupConsumeInfo) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Aggregations

MultiMQAdminCmdMethod (org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)9 MQClientException (org.apache.rocketmq.client.exception.MQClientException)7 ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)3 GroupList (org.apache.rocketmq.common.protocol.body.GroupList)3 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)2 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)2 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)2 GroupConsumeInfo (org.apache.rocketmq.console.model.GroupConsumeInfo)2 TopicConsumerInfo (org.apache.rocketmq.console.model.TopicConsumerInfo)2 Predicate (com.google.common.base.Predicate)1 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 RollbackStats (org.apache.rocketmq.common.admin.RollbackStats)1 BrokerStatsData (org.apache.rocketmq.common.protocol.body.BrokerStatsData)1