Search in sources :

Example 1 with TopicList

use of org.apache.rocketmq.common.protocol.body.TopicList in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class GroupConsumeInfo method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        // 查询特定consumer
        if (commandLine.hasOption('g')) {
            String consumerGroup = commandLine.getOptionValue('g').trim();
            ConsumeStats consumeStats = defaultMQAdminExt.examineConsumeStats(consumerGroup);
            List<MessageQueue> mqList = new LinkedList<MessageQueue>();
            mqList.addAll(consumeStats.getOffsetTable().keySet());
            Collections.sort(mqList);
            Map<MessageQueue, String> messageQueueAllocationResult = getMessageQueueAllocationResult(defaultMQAdminExt, consumerGroup);
            System.out.printf("%-32s  %-32s  %-4s  %-20s  %-20s  %-20s %-20s  %s%n", "#Topic", "#Broker Name", "#QID", "#Broker Offset", "#Consumer Offset", "#Client IP", "#Diff", "#LastTime");
            long diffTotal = 0L;
            for (MessageQueue mq : mqList) {
                OffsetWrapper offsetWrapper = consumeStats.getOffsetTable().get(mq);
                long diff = offsetWrapper.getBrokerOffset() - offsetWrapper.getConsumerOffset();
                diffTotal += diff;
                String lastTime = "";
                try {
                    lastTime = UtilAll.formatDate(new Date(offsetWrapper.getLastTimestamp()), UtilAll.YYYY_MM_DD_HH_MM_SS);
                } catch (Exception e) {
                }
                String clientIP = messageQueueAllocationResult.get(mq);
                System.out.printf("%-32s  %-32s  %-4d  %-20d  %-20d  %-20s %-20d  %s%n", UtilAll.frontStringAtLeast(mq.getTopic(), 32), UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), offsetWrapper.getBrokerOffset(), offsetWrapper.getConsumerOffset(), null != clientIP ? clientIP : "NA", diff, lastTime);
            }
            System.out.printf("%n");
            System.out.printf("Consume TPS: %s%n", consumeStats.getConsumeTps());
            System.out.printf("Diff Total: %d%n", diffTotal);
        } else // 查询全部
        {
            System.out.printf("%-32s  %-6s  %-24s %-5s  %-14s  %-7s  %s%n", "#Group", "#Count", "#Version", "#Type", "#Model", "#TPS", "#Diff Total");
            TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
            for (String topic : topicList.getTopicList()) {
                if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
                    String consumerGroup = topic.substring(MixAll.RETRY_GROUP_TOPIC_PREFIX.length());
                    try {
                        ConsumeStats consumeStats = null;
                        try {
                            consumeStats = defaultMQAdminExt.examineConsumeStats(consumerGroup);
                        } catch (Exception e) {
                            log.warn("examineConsumeStats exception, " + consumerGroup, e);
                        }
                        ConsumerConnection cc = null;
                        try {
                            cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
                        } catch (Exception e) {
                            log.warn("examineConsumerConnectionInfo exception, " + consumerGroup, e);
                        }
                        GroupConsumeInfo groupConsumeInfo = new GroupConsumeInfo();
                        groupConsumeInfo.setGroup(consumerGroup);
                        if (consumeStats != null) {
                            groupConsumeInfo.setConsumeTps((int) consumeStats.getConsumeTps());
                            groupConsumeInfo.setDiffTotal(consumeStats.computeTotalDiff());
                        }
                        if (cc != null) {
                            groupConsumeInfo.setCount(cc.getConnectionSet().size());
                            groupConsumeInfo.setMessageModel(cc.getMessageModel());
                            groupConsumeInfo.setConsumeType(cc.getConsumeType());
                            groupConsumeInfo.setVersion(cc.computeMinVersion());
                        }
                        System.out.printf("%-32s  %-6d  %-24s %-5s  %-14s  %-7d  %d%n", UtilAll.frontStringAtLeast(groupConsumeInfo.getGroup(), 32), groupConsumeInfo.getCount(), groupConsumeInfo.getCount() > 0 ? groupConsumeInfo.versionDesc() : "OFFLINE", groupConsumeInfo.consumeTypeDesc(), groupConsumeInfo.messageModelDesc(), groupConsumeInfo.getConsumeTps(), groupConsumeInfo.getDiffTotal());
                    } catch (Exception e) {
                        log.warn("examineConsumeStats or examineConsumerConnectionInfo exception, " + consumerGroup, e);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) LinkedList(java.util.LinkedList) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) Date(java.util.Date) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt)

Example 2 with TopicList

use of org.apache.rocketmq.common.protocol.body.TopicList in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class StatsAllSubCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
        // 第二个参数默认是32,有时候消费者长度过长显示不去,修改为52
        System.out.printf("%-32s  %-52s %12s %11s %11s %14s %14s%n", "#Topic", "#Consumer Group", "#Accumulation", "#InTPS", "#OutTPS", "#InMsg24Hour", "#OutMsg24Hour");
        boolean activeTopic = commandLine.hasOption('a');
        String selectTopic = commandLine.getOptionValue('t');
        for (String topic : topicList.getTopicList()) {
            if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                continue;
            }
            if (selectTopic != null && !selectTopic.isEmpty() && !topic.equals(selectTopic)) {
                continue;
            }
            try {
                printTopicDetail(defaultMQAdminExt, topic, activeTopic);
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 3 with TopicList

use of org.apache.rocketmq.common.protocol.body.TopicList in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MonitorService method doMonitorWork.

public void doMonitorWork() throws RemotingException, MQClientException, InterruptedException {
    long beginTime = System.currentTimeMillis();
    this.monitorListener.beginRound();
    TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
    for (String topic : topicList.getTopicList()) {
        if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
            String consumerGroup = topic.substring(MixAll.RETRY_GROUP_TOPIC_PREFIX.length());
            try {
                this.reportUndoneMsgs(consumerGroup);
            } catch (Exception e) {
            // log.error("reportUndoneMsgs Exception", e);
            }
            try {
                this.reportConsumerRunningInfo(consumerGroup);
            } catch (Exception e) {
            // log.error("reportConsumerRunningInfo Exception", e);
            }
        }
    }
    this.monitorListener.endRound();
    long spentTimeMills = System.currentTimeMillis() - beginTime;
    log.info("Execute one round monitor work, spent timemills: {}", spentTimeMills);
}
Also used : TopicList(org.apache.rocketmq.common.protocol.body.TopicList) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 4 with TopicList

use of org.apache.rocketmq.common.protocol.body.TopicList in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtTest method testFetchAllTopicList.

@Test
public void testFetchAllTopicList() throws RemotingException, MQClientException, InterruptedException {
    TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
    assertThat(topicList.getTopicList().size()).isEqualTo(2);
    assertThat(topicList.getTopicList()).contains("topic_one");
}
Also used : TopicList(org.apache.rocketmq.common.protocol.body.TopicList) Test(org.junit.Test)

Example 5 with TopicList

use of org.apache.rocketmq.common.protocol.body.TopicList in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BrokerLiveInfo method getHasUnitSubUnUnitTopicList.

public byte[] getHasUnitSubUnUnitTopicList() {
    TopicList topicList = new TopicList();
    try {
        try {
            this.lock.readLock().lockInterruptibly();
            Iterator<Entry<String, List<QueueData>>> topicTableIt = this.topicQueueTable.entrySet().iterator();
            while (topicTableIt.hasNext()) {
                Entry<String, List<QueueData>> topicEntry = topicTableIt.next();
                String topic = topicEntry.getKey();
                List<QueueData> queueDatas = topicEntry.getValue();
                if (queueDatas != null && queueDatas.size() > 0 && !TopicSysFlag.hasUnitFlag(queueDatas.get(0).getTopicSynFlag()) && TopicSysFlag.hasUnitSubFlag(queueDatas.get(0).getTopicSynFlag())) {
                    topicList.getTopicList().add(topic);
                }
            }
        } finally {
            this.lock.readLock().unlock();
        }
    } catch (Exception e) {
        log.error("getAllTopicList Exception", e);
    }
    return topicList.encode();
}
Also used : Entry(java.util.Map.Entry) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

TopicList (org.apache.rocketmq.common.protocol.body.TopicList)48 MQClientException (org.apache.rocketmq.client.exception.MQClientException)21 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)16 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)13 List (java.util.List)12 LinkedList (java.util.LinkedList)10 Entry (java.util.Map.Entry)8 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)8 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)8 HashSet (java.util.HashSet)7 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)7 HashMap (java.util.HashMap)6 Iterator (java.util.Iterator)6 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)6 OffsetWrapper (org.apache.rocketmq.common.admin.OffsetWrapper)6 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)6 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)6 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)6 ArrayList (java.util.ArrayList)5 Field (java.lang.reflect.Field)4