Search in sources :

Example 76 with TopicRouteData

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

the class TopicRouteSubCommand method execute.

@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        String topic = commandLine.getOptionValue('t').trim();
        TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
        String json = topicRouteData.toJson(true);
        System.out.printf("%s%n", json);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 77 with TopicRouteData

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

the class QueryConsumeQueueCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        String topic = commandLine.getOptionValue("t").trim();
        int queueId = Integer.valueOf(commandLine.getOptionValue("q").trim());
        long index = Long.valueOf(commandLine.getOptionValue("i").trim());
        int count = Integer.valueOf(commandLine.getOptionValue("c", "10").trim());
        String broker = null;
        if (commandLine.hasOption("b")) {
            broker = commandLine.getOptionValue("b").trim();
        }
        String consumerGroup = null;
        if (commandLine.hasOption("g")) {
            consumerGroup = commandLine.getOptionValue("g").trim();
        }
        if (broker == null || broker == "") {
            TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
            if (topicRouteData == null || topicRouteData.getBrokerDatas() == null || topicRouteData.getBrokerDatas().isEmpty()) {
                throw new Exception("No topic route data!");
            }
            broker = topicRouteData.getBrokerDatas().get(0).getBrokerAddrs().get(0L);
        }
        QueryConsumeQueueResponseBody queryConsumeQueueResponseBody = defaultMQAdminExt.queryConsumeQueue(broker, topic, queueId, index, count, consumerGroup);
        if (queryConsumeQueueResponseBody.getSubscriptionData() != null) {
            System.out.printf("Subscription data: \n%s\n", JSON.toJSONString(queryConsumeQueueResponseBody.getSubscriptionData(), true));
            System.out.print("======================================\n");
        }
        if (queryConsumeQueueResponseBody.getFilterData() != null) {
            System.out.printf("Filter data: \n%s\n", queryConsumeQueueResponseBody.getFilterData());
            System.out.print("======================================\n");
        }
        System.out.printf("Queue data: \nmax: %d, min: %d\n", queryConsumeQueueResponseBody.getMaxQueueIndex(), queryConsumeQueueResponseBody.getMinQueueIndex());
        System.out.print("======================================\n");
        if (queryConsumeQueueResponseBody.getQueueData() != null) {
            long i = index;
            for (ConsumeQueueData queueData : queryConsumeQueueResponseBody.getQueueData()) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("idx: " + i + "\n");
                stringBuilder.append(queueData.toString() + "\n");
                stringBuilder.append("======================================\n");
                System.out.print(stringBuilder.toString());
                i++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : ConsumeQueueData(org.apache.rocketmq.common.protocol.body.ConsumeQueueData) QueryConsumeQueueResponseBody(org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 78 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq by apache.

the class DefaultMQAdminExtTest method testExamineTopicRouteInfo.

@Test
public void testExamineTopicRouteInfo() throws RemotingException, MQClientException, InterruptedException {
    TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo("UnitTest");
    assertThat(topicRouteData.getBrokerDatas().get(0).getBrokerName()).isEqualTo("default-broker");
    assertThat(topicRouteData.getBrokerDatas().get(0).getCluster()).isEqualTo("default-cluster");
}
Also used : TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) Test(org.junit.Test)

Example 79 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq by apache.

the class QueryConsumeQueueCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        String topic = commandLine.getOptionValue("t").trim();
        int queueId = Integer.valueOf(commandLine.getOptionValue("q").trim());
        long index = Long.valueOf(commandLine.getOptionValue("i").trim());
        int count = Integer.valueOf(commandLine.getOptionValue("c", "10").trim());
        String broker = null;
        if (commandLine.hasOption("b")) {
            broker = commandLine.getOptionValue("b").trim();
        }
        String consumerGroup = null;
        if (commandLine.hasOption("g")) {
            consumerGroup = commandLine.getOptionValue("g").trim();
        }
        if (broker == null || broker == "") {
            TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
            if (topicRouteData == null || topicRouteData.getBrokerDatas() == null || topicRouteData.getBrokerDatas().isEmpty()) {
                throw new Exception("No topic route data!");
            }
            broker = topicRouteData.getBrokerDatas().get(0).getBrokerAddrs().get(0L);
        }
        QueryConsumeQueueResponseBody queryConsumeQueueResponseBody = defaultMQAdminExt.queryConsumeQueue(broker, topic, queueId, index, count, consumerGroup);
        if (queryConsumeQueueResponseBody.getSubscriptionData() != null) {
            System.out.printf("Subscription data: \n%s\n", JSON.toJSONString(queryConsumeQueueResponseBody.getSubscriptionData(), true));
            System.out.print("======================================\n");
        }
        if (queryConsumeQueueResponseBody.getFilterData() != null) {
            System.out.printf("Filter data: \n%s\n", queryConsumeQueueResponseBody.getFilterData());
            System.out.print("======================================\n");
        }
        System.out.printf("Queue data: \nmax: %d, min: %d\n", queryConsumeQueueResponseBody.getMaxQueueIndex(), queryConsumeQueueResponseBody.getMinQueueIndex());
        System.out.print("======================================\n");
        if (queryConsumeQueueResponseBody.getQueueData() != null) {
            long i = index;
            for (ConsumeQueueData queueData : queryConsumeQueueResponseBody.getQueueData()) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("idx: " + i + "\n");
                stringBuilder.append(queueData.toString() + "\n");
                stringBuilder.append("======================================\n");
                System.out.print(stringBuilder.toString());
                i++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : ConsumeQueueData(org.apache.rocketmq.common.protocol.body.ConsumeQueueData) QueryConsumeQueueResponseBody(org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 80 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq by apache.

the class StatsAllSubCommand method printTopicDetail.

public static void printTopicDetail(final DefaultMQAdminExt admin, final String topic, final boolean activeTopic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicRouteData topicRouteData = admin.examineTopicRouteInfo(topic);
    GroupList groupList = admin.queryTopicConsumeByWho(topic);
    double inTPS = 0;
    long inMsgCntToday = 0;
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
        if (masterAddr != null) {
            try {
                BrokerStatsData bsd = admin.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic);
                inTPS += bsd.getStatsMinute().getTps();
                inMsgCntToday += compute24HourSum(bsd);
            } catch (Exception e) {
            }
        }
    }
    if (groupList != null && !groupList.getGroupList().isEmpty()) {
        for (String group : groupList.getGroupList()) {
            double outTPS = 0;
            long outMsgCntToday = 0;
            for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (masterAddr != null) {
                    try {
                        String statsKey = String.format("%s@%s", topic, group);
                        BrokerStatsData bsd = admin.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey);
                        outTPS += bsd.getStatsMinute().getTps();
                        outMsgCntToday += compute24HourSum(bsd);
                    } catch (Exception e) {
                    }
                }
            }
            long accumulate = 0;
            try {
                ConsumeStats consumeStats = admin.examineConsumeStats(group, topic);
                if (consumeStats != null) {
                    accumulate = consumeStats.computeTotalDiff();
                    if (accumulate < 0) {
                        accumulate = 0;
                    }
                }
            } catch (Exception e) {
            }
            if (!activeTopic || (inMsgCntToday > 0) || (outMsgCntToday > 0)) {
                System.out.printf("%-32s  %-32s %12d %11.2f %11.2f %14d %14d%n", UtilAll.frontStringAtLeast(topic, 32), UtilAll.frontStringAtLeast(group, 32), accumulate, inTPS, outTPS, inMsgCntToday, outMsgCntToday);
            }
        }
    } else {
        if (!activeTopic || (inMsgCntToday > 0)) {
            System.out.printf("%-32s  %-32s %12d %11.2f %11s %14d %14s%n", UtilAll.frontStringAtLeast(topic, 32), "", 0, inTPS, "", inMsgCntToday, "NO_CONSUMER");
        }
    }
}
Also used : GroupList(org.apache.rocketmq.common.protocol.body.GroupList) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) 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) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData)

Aggregations

TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)92 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)65 ArrayList (java.util.ArrayList)25 MQClientException (org.apache.rocketmq.client.exception.MQClientException)25 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)25 HashMap (java.util.HashMap)22 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)20 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)18 List (java.util.List)16 HashSet (java.util.HashSet)13 Entry (java.util.Map.Entry)12 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)12 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)11 Field (java.lang.reflect.Field)10 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)10 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)10 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)10 DefaultMQAdminExtImpl (org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl)10