Search in sources :

Example 1 with TopicConsumerInfo

use of org.apache.rocketmq.console.model.TopicConsumerInfo 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 2 with TopicConsumerInfo

use of org.apache.rocketmq.console.model.TopicConsumerInfo in project rocketmq-externals by apache.

the class ConsumerServiceImpl method queryConsumeStatsListByTopicName.

@Override
@MultiMQAdminCmdMethod
public Map<String, /*groupName*/
TopicConsumerInfo> queryConsumeStatsListByTopicName(String topic) {
    Map<String, TopicConsumerInfo> group2ConsumerInfoMap = Maps.newHashMap();
    try {
        GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic);
        for (String group : groupList.getGroupList()) {
            List<TopicConsumerInfo> topicConsumerInfoList = null;
            try {
                topicConsumerInfoList = queryConsumeStatsList(topic, group);
            } catch (Exception ignore) {
            }
            group2ConsumerInfoMap.put(group, CollectionUtils.isEmpty(topicConsumerInfoList) ? new TopicConsumerInfo(topic) : topicConsumerInfoList.get(0));
        }
        return group2ConsumerInfoMap;
    } catch (Exception e) {
        throw propagate(e);
    }
}
Also used : GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicConsumerInfo(org.apache.rocketmq.console.model.TopicConsumerInfo) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Aggregations

MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 MultiMQAdminCmdMethod (org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)2 TopicConsumerInfo (org.apache.rocketmq.console.model.TopicConsumerInfo)2 Predicate (com.google.common.base.Predicate)1 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)1 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)1 GroupList (org.apache.rocketmq.common.protocol.body.GroupList)1 QueueStatInfo (org.apache.rocketmq.console.model.QueueStatInfo)1