com.alibaba.rocketmq.remoting.RPCHook Java Examples

The following examples show how to use com.alibaba.rocketmq.remoting.RPCHook. 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: MQClientAPIImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public MQClientAPIImpl(final NettyClientConfig nettyClientConfig, final ClientRemotingProcessor clientRemotingProcessor,
                       RPCHook rpcHook, final ClientConfig clientConfig) {
    this.clientConfig = clientConfig;
    topAddressing = new TopAddressing(MixAll.WS_ADDR, clientConfig.getUnitName());
    this.remotingClient = new NettyRemotingClient(nettyClientConfig, null);
    this.clientRemotingProcessor = clientRemotingProcessor;

    this.remotingClient.registerRPCHook(rpcHook);
    this.remotingClient.registerProcessor(RequestCode.CHECK_TRANSACTION_STATE, this.clientRemotingProcessor, null);

    this.remotingClient.registerProcessor(RequestCode.NOTIFY_CONSUMER_IDS_CHANGED, this.clientRemotingProcessor, null);

    this.remotingClient.registerProcessor(RequestCode.RESET_CONSUMER_CLIENT_OFFSET, this.clientRemotingProcessor, null);

    this.remotingClient.registerProcessor(RequestCode.GET_CONSUMER_STATUS_FROM_CLIENT, this.clientRemotingProcessor, null);

    this.remotingClient.registerProcessor(RequestCode.GET_CONSUMER_RUNNING_INFO, this.clientRemotingProcessor, null);

    this.remotingClient.registerProcessor(RequestCode.CONSUME_MESSAGE_DIRECTLY, this.clientRemotingProcessor, null);
}
 
Example #2
Source File: DeleteTopicSubCommand.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(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: QueryMsgByKeySubCommand.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(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 #4
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 #5
Source File: QueryMsgByIdSubCommand.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 {
        defaultMQAdminExt.start();

        final String msgId = commandLine.getOptionValue('i').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, msgId);
            System.out.println(result);
        } else {

            queryById(defaultMQAdminExt, msgId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #6
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 #7
Source File: UpdateKvConfigCommand.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(CommandLine commandLine, Options options, RPCHook rpcHook) {
    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");
        return;
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #8
Source File: DeleteKvConfigCommand.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(CommandLine commandLine, Options options, RPCHook rpcHook) {
    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();

        defaultMQAdminExt.start();
        defaultMQAdminExt.deleteKvConfig(namespace, key);
        System.out.printf("delete kv config from namespace success.\n");
        return;
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #9
Source File: TopicClusterSubCommand.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()));
    String topic = commandLine.getOptionValue('t').trim();
    try {
        defaultMQAdminExt.start();
        Set<String> clusters = defaultMQAdminExt.getTopicClusterList(topic);
        for (String value : clusters){
            System.out.println(value);
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #10
Source File: DeleteTopicSubCommand.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 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 #11
Source File: CleanExpiredCQSubCommand.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 {
        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.println(result ? "success" : "false");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #12
Source File: CleanUnusedTopicCommand.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 {
        boolean result = false;
        defaultMQAdminExt.start();
        if (commandLine.hasOption('b')) {
            String addr = commandLine.getOptionValue('b').trim();
            result = defaultMQAdminExt.cleanUnusedTopicByAddr(addr);

        } else {
            String cluster = commandLine.getOptionValue('c');
            if (null != cluster)
                cluster = cluster.trim();
            result = defaultMQAdminExt.cleanUnusedTopicByAddr(cluster);
        }
        System.out.println(result ? "success" : "false");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #13
Source File: MonitorService.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
public static void main0(String[] args, RPCHook rpcHook) throws MQClientException {
    final MonitorService monitorService =
            new MonitorService(new MonitorConfig(), new DefaultMonitorListener(), rpcHook);
    monitorService.start();

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        private volatile boolean hasShutdown = false;


        @Override
        public void run() {
            synchronized (this) {
                if (!this.hasShutdown) {
                    this.hasShutdown = true;
                    monitorService.shutdown();
                }
            }
        }
    }, "ShutdownHook"));
}
 
Example #14
Source File: UpdateKvConfigCommand.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 {
        // 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");
        return;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #15
Source File: DeleteKvConfigCommand.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 {
        // namespace
        String namespace = commandLine.getOptionValue('s').trim();
        // key name
        String key = commandLine.getOptionValue('k').trim();

        defaultMQAdminExt.start();
        defaultMQAdminExt.deleteKvConfig(namespace, key);
        System.out.printf("delete kv config from namespace success.%n");
        return;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #16
Source File: CheckMsgSubCommand.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) {
    Store store = new Store(commandLine.getOptionValue("cStorePath").trim(), //
        Integer.parseInt(commandLine.getOptionValue("cSize").trim()),//
        commandLine.getOptionValue("lStorePath").trim(), //
        Integer.parseInt(commandLine.getOptionValue("lSize").trim()));
    store.load();
    store.traval(false);
}
 
Example #17
Source File: ProducerConnectionSubCommand.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 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) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #18
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 #19
Source File: CheckMsgSubCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    Store store = new Store(commandLine.getOptionValue("cStorePath").trim(), //
        Integer.parseInt(commandLine.getOptionValue("cSize").trim()),//
        commandLine.getOptionValue("lStorePath").trim(), //
        Integer.parseInt(commandLine.getOptionValue("lSize").trim()));
    store.load();
    store.traval(false);
}
 
Example #20
Source File: StartMonitoringSubCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    try {
        MonitorService monitorService =
                new MonitorService(new MonitorConfig(), new DefaultMonitorListener(), rpcHook);

        monitorService.start();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
    }
}
 
Example #21
Source File: MQClientInstance.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public MQClientInstance(ClientConfig clientConfig, int instanceIndex, String clientId, RPCHook rpcHook) {
    this.clientConfig = clientConfig;
    this.instanceIndex = instanceIndex;
    this.nettyClientConfig = new NettyClientConfig();
    this.nettyClientConfig.setClientCallbackExecutorThreads(clientConfig.getClientCallbackExecutorThreads());
    this.clientRemotingProcessor = new ClientRemotingProcessor(this);
    this.mQClientAPIImpl =
            new MQClientAPIImpl(this.nettyClientConfig, this.clientRemotingProcessor, rpcHook, clientConfig.getUnitName());

    if (this.clientConfig.getNamesrvAddr() != null) {
        this.mQClientAPIImpl.updateNameServerAddressList(this.clientConfig.getNamesrvAddr());
        log.info("user specified name server address: {}", this.clientConfig.getNamesrvAddr());
    }

    this.clientId = clientId;

    this.mQAdminImpl = new MQAdminImpl(this);

    this.pullMessageService = new PullMessageService(this);

    this.rebalanceService = new RebalanceService(this);

    this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
    this.defaultMQProducer.resetClientConfig(clientConfig);

    this.consumerStatsManager = new ConsumerStatsManager(this.scheduledExecutorService);

    log.info("created a new client Instance, FactoryIndex: {} ClinetID: {} {} {}, serializeType={}",//
        this.instanceIndex, //
        this.clientId, //
        this.clientConfig, //
        MQVersion.getVersionDesc(MQVersion.CurrentVersion), RemotingCommand.getSerializeTypeConfigInThisServer());
}
 
Example #22
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) {
    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 != null && !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 #23
Source File: MQClientInstance.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public MQClientInstance(ClientConfig clientConfig, int instanceIndex, String clientId, RPCHook rpcHook) {
    this.clientConfig = clientConfig;
    this.instanceIndex = instanceIndex;
    this.nettyClientConfig = new NettyClientConfig();
    this.nettyClientConfig.setClientCallbackExecutorThreads(clientConfig.getClientCallbackExecutorThreads());
    this.clientRemotingProcessor = new ClientRemotingProcessor(this);
    this.mQClientAPIImpl = new MQClientAPIImpl(this.nettyClientConfig, this.clientRemotingProcessor, rpcHook, clientConfig);

    if (this.clientConfig.getNamesrvAddr() != null) {
        this.mQClientAPIImpl.updateNameServerAddressList(this.clientConfig.getNamesrvAddr());
        log.info("user specified name server address: {}", this.clientConfig.getNamesrvAddr());
    }

    this.clientId = clientId;

    this.mQAdminImpl = new MQAdminImpl(this);

    this.pullMessageService = new PullMessageService(this);

    this.rebalanceService = new RebalanceService(this);

    this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
    this.defaultMQProducer.resetClientConfig(clientConfig);

    this.consumerStatsManager = new ConsumerStatsManager(this.scheduledExecutorService);

    log.info("created a new client Instance, FactoryIndex: {} ClinetID: {} {} {}, serializeType={}", //
            this.instanceIndex, //
            this.clientId, //
            this.clientConfig, //
            MQVersion.getVersionDesc(MQVersion.CurrentVersion), RemotingCommand.getSerializeTypeConfigInThisServer());
}
 
Example #24
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 #25
Source File: ClusterListSubCommand.java    From rocketmq with Apache License 2.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 #26
Source File: QueryMsgByIdSubCommand.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();

        final String msgId = commandLine.getOptionValue('i').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, msgId);
            System.out.println(result);
        }
        else {

            queryById(defaultMQAdminExt, msgId);
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #27
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 #28
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 #29
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) {
    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) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #30
Source File: AllocateMQSubCommand.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 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();
    }
}