Java Code Examples for org.apache.rocketmq.tools.admin.DefaultMQAdminExt#setInstanceName()

The following examples show how to use org.apache.rocketmq.tools.admin.DefaultMQAdminExt#setInstanceName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopicRouteSubCommand.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 2
Source File: TopicClusterSubCommand.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    String topic = commandLine.getOptionValue('t').trim();
    try {
        defaultMQAdminExt.start();
        Set<String> clusters = defaultMQAdminExt.getTopicClusterList(topic);
        for (String value : clusters) {
            System.out.printf("%s%n", value);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 3
Source File: QueryMsgByUniqueKeySubCommand.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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();

        final String msgId = commandLine.getOptionValue('i').trim();
        final String topic = commandLine.getOptionValue('t').trim();
        if (commandLine.hasOption('g') && commandLine.hasOption('d')) {
            final String consumerGroup = commandLine.getOptionValue('g').trim();
            final String clientId = commandLine.getOptionValue('d').trim();
            ConsumeMessageDirectlyResult result =
                defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, topic, msgId);
            System.out.printf("%s", result);
        } else {
            queryById(defaultMQAdminExt, topic, msgId);
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 4
Source File: CleanExpiredCQSubCommand.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        boolean result = false;
        defaultMQAdminExt.start();
        if (commandLine.hasOption('b')) {
            String addr = commandLine.getOptionValue('b').trim();
            result = defaultMQAdminExt.cleanExpiredConsumerQueueByAddr(addr);

        } else {
            String cluster = commandLine.getOptionValue('c');
            if (null != cluster)
                cluster = cluster.trim();
            result = defaultMQAdminExt.cleanExpiredConsumerQueue(cluster);
        }
        System.out.printf(result ? "success" : "false");
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 5
Source File: MQAdmin.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static boolean createTopic(String nameSrvAddr, String clusterName, String topic,
    int queueNum, int waitTimeSec) {
    boolean createResult = false;
    DefaultMQAdminExt mqAdminExt = new DefaultMQAdminExt();
    mqAdminExt.setInstanceName(UUID.randomUUID().toString());
    mqAdminExt.setNamesrvAddr(nameSrvAddr);
    try {
        mqAdminExt.start();
        mqAdminExt.createTopic(clusterName, topic, queueNum);
    } catch (Exception e) {
    }

    long startTime = System.currentTimeMillis();
    while (!createResult) {
        createResult = checkTopicExist(mqAdminExt, topic);
        if (System.currentTimeMillis() - startTime < waitTimeSec * 1000) {
            TestUtils.waitForMoment(100);
        } else {
            log.error(String.format("timeout,but create topic[%s] failed!", topic));
            break;
        }
    }

    mqAdminExt.shutdown();
    return createResult;
}
 
Example 6
Source File: TopicClusterSubCommand.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@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()));
    String topic = commandLine.getOptionValue('t').trim();
    try {
        defaultMQAdminExt.start();
        Set<String> clusters = defaultMQAdminExt.getTopicClusterList(topic);
        for (String value : clusters) {
            System.out.printf("%s%n", value);
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 7
Source File: UpdateKvConfigCommand.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        // namespace
        String namespace = commandLine.getOptionValue('s').trim();
        // key name
        String key = commandLine.getOptionValue('k').trim();
        // key name
        String value = commandLine.getOptionValue('v').trim();

        defaultMQAdminExt.start();
        defaultMQAdminExt.createAndUpdateKvConfig(namespace, key, value);
        System.out.printf("create or update kv config to namespace success.%n");
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 8
Source File: CloneGroupOffsetCommand.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    String srcGroup = commandLine.getOptionValue("s").trim();
    String destGroup = commandLine.getOptionValue("d").trim();
    String topic = commandLine.getOptionValue("t").trim();

    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName("admin-" + Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();
        ConsumeStats consumeStats = defaultMQAdminExt.examineConsumeStats(srcGroup);
        Set<MessageQueue> mqs = consumeStats.getOffsetTable().keySet();
        if (!mqs.isEmpty()) {
            TopicRouteData topicRoute = defaultMQAdminExt.examineTopicRouteInfo(topic);
            for (MessageQueue mq : mqs) {
                String addr = null;
                for (BrokerData brokerData : topicRoute.getBrokerDatas()) {
                    if (brokerData.getBrokerName().equals(mq.getBrokerName())) {
                        addr = brokerData.selectBrokerAddr();
                        break;
                    }
                }
                long offset = consumeStats.getOffsetTable().get(mq).getBrokerOffset();
                if (offset >= 0) {
                    defaultMQAdminExt.updateConsumeOffset(addr, destGroup, mq, offset);
                }
            }
        }
        System.out.printf("clone group offset success. srcGroup[%s], destGroup=[%s], topic[%s]",
            srcGroup, destGroup, topic);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 9
Source File: CloneGroupOffsetCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    String srcGroup = commandLine.getOptionValue("s").trim();
    String destGroup = commandLine.getOptionValue("d").trim();
    String topic = commandLine.getOptionValue("t").trim();

    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName("admin-" + Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();
        ConsumeStats consumeStats = defaultMQAdminExt.examineConsumeStats(srcGroup);
        Set<MessageQueue> mqs = consumeStats.getOffsetTable().keySet();
        if (!mqs.isEmpty()) {
            TopicRouteData topicRoute = defaultMQAdminExt.examineTopicRouteInfo(topic);
            for (MessageQueue mq : mqs) {
                String addr = null;
                for (BrokerData brokerData : topicRoute.getBrokerDatas()) {
                    if (brokerData.getBrokerName().equals(mq.getBrokerName())) {
                        addr = brokerData.selectBrokerAddr();
                        break;
                    }
                }
                long offset = consumeStats.getOffsetTable().get(mq).getBrokerOffset();
                if (offset >= 0) {
                    defaultMQAdminExt.updateConsumeOffset(addr, destGroup, mq, offset);
                }
            }
        }
        System.out.printf("clone group offset success. srcGroup[%s], destGroup=[%s], topic[%s]",
            srcGroup, destGroup, topic);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 10
Source File: ProducerConnectionSubCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@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();

        String group = commandLine.getOptionValue('g').trim();
        String topic = commandLine.getOptionValue('t').trim();

        ProducerConnection pc = defaultMQAdminExt.examineProducerConnectionInfo(group, topic);

        int i = 1;
        for (Connection conn : pc.getConnectionSet()) {
            System.out.printf("%04d  %-32s %-22s %-8s %s%n",
                i++,
                conn.getClientId(),
                conn.getClientAddr(),
                conn.getLanguage(),
                MQVersion.getVersionDesc(conn.getVersion())
            );
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 11
Source File: CloneGroupOffsetCommand.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    String srcGroup = commandLine.getOptionValue("s").trim();
    String destGroup = commandLine.getOptionValue("d").trim();
    String topic = commandLine.getOptionValue("t").trim();

    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName("admin-" + Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();
        ConsumeStats consumeStats = defaultMQAdminExt.examineConsumeStats(srcGroup);
        Set<MessageQueue> mqs = consumeStats.getOffsetTable().keySet();
        if (!mqs.isEmpty()) {
            TopicRouteData topicRoute = defaultMQAdminExt.examineTopicRouteInfo(topic);
            for (MessageQueue mq : mqs) {
                String addr = null;
                for (BrokerData brokerData : topicRoute.getBrokerDatas()) {
                    if (brokerData.getBrokerName().equals(mq.getBrokerName())) {
                        addr = brokerData.selectBrokerAddr();
                        break;
                    }
                }
                long offset = consumeStats.getOffsetTable().get(mq).getBrokerOffset();
                if (offset >= 0) {
                    defaultMQAdminExt.updateConsumeOffset(addr, destGroup, mq, offset);
                }
            }
        }
        System.out.printf("clone group offset success. srcGroup[%s], destGroup=[%s], topic[%s]",
            srcGroup, destGroup, topic);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 12
Source File: ConsumerConnectionSubCommand.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@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();

        String group = commandLine.getOptionValue('g').trim();

        ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(group);

        int i = 1;
        for (Connection conn : cc.getConnectionSet()) {
            System.out.printf("%03d  %-32s %-22s %-8s %s%n",
                i++,
                conn.getClientId(),
                conn.getClientAddr(),
                conn.getLanguage(),
                MQVersion.getVersionDesc(conn.getVersion())
            );
        }

        System.out.printf("%nBelow is subscription:");
        Iterator<Entry<String, SubscriptionData>> it = cc.getSubscriptionTable().entrySet().iterator();
        i = 1;
        while (it.hasNext()) {
            Entry<String, SubscriptionData> entry = it.next();
            SubscriptionData sd = entry.getValue();
            System.out.printf("%03d  Topic: %-40s SubExpression: %s%n",
                i++,
                sd.getTopic(),
                sd.getSubString()
            );
        }

        System.out.printf("");
        System.out.printf("ConsumeType: %s%n", cc.getConsumeType());
        System.out.printf("MessageModel: %s%n", cc.getMessageModel());
        System.out.printf("ConsumeFromWhere: %s%n", cc.getConsumeFromWhere());
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 13
Source File: QueryConsumeQueueCommand.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@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();
    }
}
 
Example 14
Source File: QueryConsumeQueueCommand.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@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();
    }
}
 
Example 15
Source File: QueryMsgByOffsetSubCommand.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP, rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        String topic = commandLine.getOptionValue('t').trim();
        String brokerName = commandLine.getOptionValue('b').trim();
        String queueId = commandLine.getOptionValue('i').trim();
        String offset = commandLine.getOptionValue('o').trim();

        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();
        defaultMQAdminExt.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
                case FOUND:
                    QueryMsgByIdSubCommand.printMsg(defaultMQAdminExt, pullResult.getMsgFoundList().get(0));
                    break;
                case NO_MATCHED_MSG:
                case NO_NEW_MSG:
                case OFFSET_ILLEGAL:
                default:
                    break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQPullConsumer.shutdown();
        defaultMQAdminExt.shutdown();
    }
}
 
Example 16
Source File: GetConsumerStatusCommand.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        String group = commandLine.getOptionValue("g").trim();
        String topic = commandLine.getOptionValue("t").trim();
        String originClientId = "";
        if (commandLine.hasOption("i")) {
            originClientId = commandLine.getOptionValue("i").trim();
        }
        defaultMQAdminExt.start();

        Map<String, Map<MessageQueue, Long>> consumerStatusTable =
            defaultMQAdminExt.getConsumeStatus(topic, group, originClientId);
        System.out.printf("get consumer status from client. group=%s, topic=%s, originClientId=%s%n",
            group, topic, originClientId);

        System.out.printf("%-50s  %-15s  %-15s  %-20s%n",
            "#clientId",
            "#brokerName",
            "#queueId",
            "#offset");

        for (Map.Entry<String, Map<MessageQueue, Long>> entry : consumerStatusTable.entrySet()) {
            String clientId = entry.getKey();
            Map<MessageQueue, Long> mqTable = entry.getValue();
            for (Map.Entry<MessageQueue, Long> entry1 : mqTable.entrySet()) {
                MessageQueue mq = entry1.getKey();
                System.out.printf("%-50s  %-15s  %-15d  %-20d%n",
                    UtilAll.frontStringAtLeast(clientId, 50),
                    mq.getBrokerName(),
                    mq.getQueueId(),
                    mqTable.get(mq));
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 17
Source File: ConsumerConnectionSubCommand.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@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 group = commandLine.getOptionValue('g').trim();

        ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(group);

        int i = 1;
        for (Connection conn : cc.getConnectionSet()) {
            System.out.printf("%03d  %-32s %-22s %-8s %s%n",
                i++,
                conn.getClientId(),
                conn.getClientAddr(),
                conn.getLanguage(),
                MQVersion.getVersionDesc(conn.getVersion())
            );
        }

        System.out.printf("%nBelow is subscription:");
        Iterator<Entry<String, SubscriptionData>> it = cc.getSubscriptionTable().entrySet().iterator();
        i = 1;
        while (it.hasNext()) {
            Entry<String, SubscriptionData> entry = it.next();
            SubscriptionData sd = entry.getValue();
            System.out.printf("%03d  Topic: %-40s SubExpression: %s%n",
                i++,
                sd.getTopic(),
                sd.getSubString()
            );
        }

        System.out.printf("");
        System.out.printf("ConsumeType: %s%n", cc.getConsumeType());
        System.out.printf("MessageModel: %s%n", cc.getMessageModel());
        System.out.printf("ConsumeFromWhere: %s%n", cc.getConsumeFromWhere());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 18
Source File: GetBrokerConfigCommand.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(final CommandLine commandLine, final Options options,
    final RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {

        if (commandLine.hasOption('b')) {
            String brokerAddr = commandLine.getOptionValue('b').trim();
            defaultMQAdminExt.start();

            getAndPrint(defaultMQAdminExt,
                String.format("============%s============\n", brokerAddr),
                brokerAddr);

        } else if (commandLine.hasOption('c')) {
            String clusterName = commandLine.getOptionValue('c').trim();
            defaultMQAdminExt.start();

            Map<String, List<String>> masterAndSlaveMap
                = CommandUtil.fetchMasterAndSlaveDistinguish(defaultMQAdminExt, clusterName);

            for (String masterAddr : masterAndSlaveMap.keySet()) {

                getAndPrint(
                    defaultMQAdminExt,
                    String.format("============Master: %s============\n", masterAddr),
                    masterAddr
                );
                for (String slaveAddr : masterAndSlaveMap.get(masterAddr)) {

                    getAndPrint(
                        defaultMQAdminExt,
                        String.format("============My Master: %s=====Slave: %s============\n", masterAddr, slaveAddr),
                        slaveAddr
                    );
                }
            }
        }

    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 19
Source File: QueryMsgByOffsetSubCommand.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP, rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        String topic = commandLine.getOptionValue('t').trim();
        String brokerName = commandLine.getOptionValue('b').trim();
        String queueId = commandLine.getOptionValue('i').trim();
        String offset = commandLine.getOptionValue('o').trim();

        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(brokerName);
        mq.setQueueId(Integer.parseInt(queueId));

        defaultMQPullConsumer.start();
        defaultMQAdminExt.start();

        PullResult pullResult = defaultMQPullConsumer.pull(mq, "*", Long.parseLong(offset), 1);
        if (pullResult != null) {
            switch (pullResult.getPullStatus()) {
                case FOUND:
                    QueryMsgByIdSubCommand.printMsg(defaultMQAdminExt, pullResult.getMsgFoundList().get(0));
                    break;
                case NO_MATCHED_MSG:
                case NO_NEW_MSG:
                case OFFSET_ILLEGAL:
                default:
                    break;
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQPullConsumer.shutdown();
        defaultMQAdminExt.shutdown();
    }
}
 
Example 20
Source File: GetConsumerStatusCommand.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        String group = commandLine.getOptionValue("g").trim();
        String topic = commandLine.getOptionValue("t").trim();
        String originClientId = "";
        if (commandLine.hasOption("i")) {
            originClientId = commandLine.getOptionValue("i").trim();
        }
        defaultMQAdminExt.start();

        Map<String, Map<MessageQueue, Long>> consumerStatusTable =
            defaultMQAdminExt.getConsumeStatus(topic, group, originClientId);
        System.out.printf("get consumer status from client. group=%s, topic=%s, originClientId=%s%n",
            group, topic, originClientId);

        System.out.printf("%-50s  %-15s  %-15s  %-20s%n",
            "#clientId",
            "#brokerName",
            "#queueId",
            "#offset");

        for (Map.Entry<String, Map<MessageQueue, Long>> entry : consumerStatusTable.entrySet()) {
            String clientId = entry.getKey();
            Map<MessageQueue, Long> mqTable = entry.getValue();
            for (Map.Entry<MessageQueue, Long> entry1 : mqTable.entrySet()) {
                MessageQueue mq = entry1.getKey();
                System.out.printf("%-50s  %-15s  %-15d  %-20d%n",
                    UtilAll.frontStringAtLeast(clientId, 50),
                    mq.getBrokerName(),
                    mq.getQueueId(),
                    mqTable.get(mq));
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}