Java Code Examples for com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt#setInstanceName()

The following examples show how to use com.alibaba.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: QueryMsgByKeySubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 6 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 {
        final String topic = commandLine.getOptionValue('t').trim();
        final String key = commandLine.getOptionValue('k').trim();

        this.queryByKey(defaultMQAdminExt, topic, key);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 2
Source File: DeleteTopicSubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
    adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        String topic = commandLine.getOptionValue('t').trim();

        if (commandLine.hasOption('c')) {
            String clusterName = commandLine.getOptionValue('c').trim();

            adminExt.start();
            deleteTopic(adminExt, clusterName, topic);
            return;
        }

        ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        adminExt.shutdown();
    }
}
 
Example 3
Source File: TopicRouteSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.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()));

    try {
        defaultMQAdminExt.start();

        String topic = commandLine.getOptionValue('t').trim();
        TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
        String json = topicRouteData.toJson(true);
        System.out.println(json);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 4
Source File: TopicRouteSubCommand.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()));

    try {
        defaultMQAdminExt.start();

        String topic = commandLine.getOptionValue('t').trim();
        TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
        String json = topicRouteData.toJson(true);
        System.out.println(json);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 5
Source File: QueryMsgByKeySubCommand.java    From rocketmq with Apache License 2.0 6 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 {
        final String topic = commandLine.getOptionValue('t').trim();
        final String key = commandLine.getOptionValue('k').trim();

        this.queryByKey(defaultMQAdminExt, topic, key);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 6
Source File: UpdateProjectGroupCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 6 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 {
        String namespace = NamesrvUtil.NAMESPACE_PROJECT_CONFIG;
        String ip = commandLine.getOptionValue('i').trim();
        String project = commandLine.getOptionValue('p').trim();

        defaultMQAdminExt.start();
        defaultMQAdminExt.createAndUpdateKvConfig(namespace, ip, project);
        System.out.printf("create or update kv config to namespace success.\n");
        return;
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 7
Source File: MQAdminInstance.java    From rocket-console with Apache License 2.0 5 votes vote down vote up
public static void initMQAdminInstance() throws MQClientException {
    Integer nowCount = initCounter.get();
    if (nowCount == null) {
        DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
        defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
        defaultMQAdminExt.start();
        mqAdminExtThreadLocal.set(defaultMQAdminExt);
        initCounter.set(1);
    } else {
        initCounter.set(nowCount + 1);
    }

}
 
Example 8
Source File: ClusterTestRequestProcessor.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public ClusterTestRequestProcessor(NamesrvController namesrvController, String productEnvName) {
    super(namesrvController);
    this.productEnvName = productEnvName;
    adminExt = new DefaultMQAdminExt();
    adminExt.setInstanceName("CLUSTER_TEST_NS_INS_" + productEnvName);
    adminExt.setUnitName(productEnvName);
    try {
        adminExt.start();
    } catch (MQClientException e) {
        e.printStackTrace();
    }
}
 
Example 9
Source File: AllocateMQSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
    adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        adminExt.start();

        String topic = commandLine.getOptionValue('t').trim();
        String ips = commandLine.getOptionValue('i').trim();
        final String[] split = ips.split(",");
        final List<String> ipList = new LinkedList<String>();
        for (String ip : split) {
            ipList.add(ip);
        }

        final TopicRouteData topicRouteData = adminExt.examineTopicRouteInfo(topic);
        final Set<MessageQueue> mqs = MQClientInstance.topicRouteData2TopicSubscribeInfo(topic, topicRouteData);

        final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely();


        RebalanceResult rr = new RebalanceResult();

        for (String i : ipList) {
            final List<MessageQueue> mqResult = averagely.allocate("aa", i, new ArrayList<MessageQueue>(mqs), ipList);
            rr.getResult().put(i, mqResult);
        }

        final String json = RemotingSerializable.toJson(rr, false);
        System.out.println(json);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        adminExt.shutdown();
    }
}
 
Example 10
Source File: ClusterListSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 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()));

    long printInterval = 1;
    boolean enableInterval = commandLine.hasOption('i');

    if (enableInterval) {
        printInterval = Long.parseLong(commandLine.getOptionValue('i')) * 1000;
    }

    try {
        defaultMQAdminExt.start();

        do {
            if (commandLine.hasOption('m')) {
                this.printClusterMoreStats(defaultMQAdminExt);
            }
            else {
                this.printClusterBaseInfo(defaultMQAdminExt);
            }

            Thread.sleep(printInterval);

            System.out.println("");
        } while (enableInterval);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 11
Source File: BrokerStatusSubCommand.java    From rocketmq with Apache License 2.0 5 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 brokerAddr = commandLine.getOptionValue('b').trim();

        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(brokerAddr);


        TreeMap<String, String> tmp = new TreeMap<String, String>();
        tmp.putAll(kvTable.getTable());

        Iterator<Entry<String, String>> it = tmp.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, String> next = it.next();
            System.out.printf("%-32s: %s%n", next.getKey(), next.getValue());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 12
Source File: CloneGroupOffsetCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 5 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 {
        String srcGroup = commandLine.getOptionValue("s").trim();
        String destGroup = commandLine.getOptionValue("d").trim();
        String topic = "";
        if (commandLine.hasOption('t')) {
            topic = commandLine.getOptionValue("t").trim();
        }

        boolean isOffline = false;
        if (commandLine.hasOption('o')) {
            isOffline = Boolean.parseBoolean(commandLine.getOptionValue("o").trim());
        }

        defaultMQAdminExt.start();
        defaultMQAdminExt.cloneGroupOffset(srcGroup, destGroup, topic, isOffline);
        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 13
Source File: BrokerStatusSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 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 brokerAddr = commandLine.getOptionValue('b').trim();

        //获取broker一些全局统计信息 例如commitlog  全局offset等信息
        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(brokerAddr);

        TreeMap<String, String> tmp = new TreeMap<String, String>();
        tmp.putAll(kvTable.getTable());

        Iterator<Entry<String, String>> it = tmp.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, String> next = it.next();
            System.out.printf("%-32s: %s\n", next.getKey(), next.getValue());
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 14
Source File: CloneGroupOffsetCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 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 {
        String srcGroup = commandLine.getOptionValue("s").trim();
        String destGroup = commandLine.getOptionValue("d").trim();
        String topic = "";
        if (commandLine.hasOption('t')) {
            topic = commandLine.getOptionValue("t").trim();
        }

        boolean isOffline = false;
        if (commandLine.hasOption('o')) {
            isOffline = Boolean.parseBoolean(commandLine.getOptionValue("o").trim());
        }

        defaultMQAdminExt.start();
        defaultMQAdminExt.cloneGroupOffset(srcGroup, destGroup, topic, isOffline);
        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 15
Source File: AbstractService.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
protected DefaultMQAdminExt getDefaultMQAdminExt() {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    return defaultMQAdminExt;
}
 
Example 16
Source File: TopicStatusSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 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()));

    try {
        defaultMQAdminExt.start();

        String topic = commandLine.getOptionValue('t').trim();
        TopicStatsTable topicStatsTable = defaultMQAdminExt.examineTopicStats(topic);

        List<MessageQueue> mqList = new LinkedList<MessageQueue>();
        mqList.addAll(topicStatsTable.getOffsetTable().keySet());
        Collections.sort(mqList);

        System.out.printf("%-32s  %-4s  %-20s  %-20s    %s\n",//
            "#Broker Name",//
            "#QID",//
            "#Min Offset",//
            "#Max Offset",//
            "#Last Updated" //
        );

        for (MessageQueue mq : mqList) {
            TopicOffset topicOffset = topicStatsTable.getOffsetTable().get(mq);

            String humanTimestamp = "";
            if (topicOffset.getLastUpdateTimestamp() > 0) {
                humanTimestamp = UtilAll.timeMillisToHumanString2(topicOffset.getLastUpdateTimestamp());
            }

            System.out.printf("%-32s  %-4d  %-20d  %-20d    %s\n",//
                UtilAll.frontStringAtLeast(mq.getBrokerName(), 32),//
                mq.getQueueId(),//
                topicOffset.getMinOffset(),//
                topicOffset.getMaxOffset(),//
                humanTimestamp //
                );
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 17
Source File: QueryMsgByOffsetSubCommand.java    From RocketMQ-Master-analyze 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);

    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.queryById(defaultMQAdminExt,
                    pullResult.getMsgFoundList().get(0).getMsgId());
                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 18
Source File: GetConsumerStatusCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.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 {
        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");

        Iterator<String> clientIterator = consumerStatusTable.keySet().iterator();
        while (clientIterator.hasNext()) {
            String clientId = clientIterator.next();
            Map<MessageQueue, Long> mqTable = consumerStatusTable.get(clientId);
            Iterator<MessageQueue> mqIterator = mqTable.keySet().iterator();
            while (mqIterator.hasNext()) {
                MessageQueue mq = mqIterator.next();
                System.out.printf("%-50s  %-15s  %-15d  %-20d\n",//
                    UtilAll.frontStringAtLeast(clientId, 50),//
                    mq.getBrokerName(),//
                    mq.getQueueId(),//
                    mqTable.get(mq));
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 19
Source File: GetConsumerStatusCommand.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 {
        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) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 20
Source File: TopicStatusSubCommand.java    From rocketmq with Apache License 2.0 4 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()));

    try {
        defaultMQAdminExt.start();

        String topic = commandLine.getOptionValue('t').trim();
        TopicStatsTable topicStatsTable = defaultMQAdminExt.examineTopicStats(topic);

        List<MessageQueue> mqList = new LinkedList<MessageQueue>();
        mqList.addAll(topicStatsTable.getOffsetTable().keySet());
        Collections.sort(mqList);

        System.out.printf("%-32s  %-4s  %-20s  %-20s    %s%n",//
                "#Broker Name",//
                "#QID",//
                "#Min Offset",//
                "#Max Offset",//
                "#Last Updated" //
        );

        for (MessageQueue mq : mqList) {
            TopicOffset topicOffset = topicStatsTable.getOffsetTable().get(mq);

            String humanTimestamp = "";
            if (topicOffset.getLastUpdateTimestamp() > 0) {
                humanTimestamp = UtilAll.timeMillisToHumanString2(topicOffset.getLastUpdateTimestamp());
            }

            System.out.printf("%-32s  %-4d  %-20d  %-20d    %s%n",//
                    UtilAll.frontStringAtLeast(mq.getBrokerName(), 32),//
                    mq.getQueueId(),//
                    topicOffset.getMinOffset(),//
                    topicOffset.getMaxOffset(),//
                    humanTimestamp //
            );
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}