Search in sources :

Example 56 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class StartMonitoringSubCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    try {
        MonitorService monitorService = new MonitorService(new MonitorConfig(), new DefaultMonitorListener(), rpcHook);
        monitorService.start();
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    }
}
Also used : SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MonitorService(org.apache.rocketmq.tools.monitor.MonitorService) DefaultMonitorListener(org.apache.rocketmq.tools.monitor.DefaultMonitorListener) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MonitorConfig(org.apache.rocketmq.tools.monitor.MonitorConfig)

Example 57 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class QueryMsgByIdSubCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    DefaultMQProducer defaultMQProducer = new DefaultMQProducer("ReSendMsgById");
    defaultMQProducer.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        if (commandLine.hasOption('s')) {
            if (commandLine.hasOption('u')) {
                String unitName = commandLine.getOptionValue('u').trim();
                defaultMQProducer.setUnitName(unitName);
            }
            defaultMQProducer.start();
        }
        final String msgIds = commandLine.getOptionValue('i').trim();
        final String[] msgIdArr = StringUtils.split(msgIds, ",");
        if (commandLine.hasOption('g') && commandLine.hasOption('d')) {
            final String consumerGroup = commandLine.getOptionValue('g').trim();
            final String clientId = commandLine.getOptionValue('d').trim();
            for (String msgId : msgIdArr) {
                if (StringUtils.isNotBlank(msgId)) {
                    pushMsg(defaultMQAdminExt, consumerGroup, clientId, msgId.trim());
                }
            }
        } else if (commandLine.hasOption('s')) {
            boolean resend = Boolean.parseBoolean(commandLine.getOptionValue('s', "false").trim());
            if (resend) {
                for (String msgId : msgIdArr) {
                    if (StringUtils.isNotBlank(msgId)) {
                        sendMsg(defaultMQAdminExt, defaultMQProducer, msgId.trim());
                    }
                }
            }
        } else {
            for (String msgId : msgIdArr) {
                if (StringUtils.isNotBlank(msgId)) {
                    queryById(defaultMQAdminExt, msgId.trim());
                }
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQProducer.shutdown();
        defaultMQAdminExt.shutdown();
    }
}
Also used : SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) IOException(java.io.IOException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 58 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class QueryMsgByOffsetSubCommand method execute.

@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();
    }
}
Also used : MessageQueue(org.apache.rocketmq.common.message.MessageQueue) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) DefaultMQPullConsumer(org.apache.rocketmq.client.consumer.DefaultMQPullConsumer) PullResult(org.apache.rocketmq.client.consumer.PullResult) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException)

Example 59 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class QueryMsgByUniqueKeySubCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        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();
    }
}
Also used : ConsumeMessageDirectlyResult(org.apache.rocketmq.common.protocol.body.ConsumeMessageDirectlyResult) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) IOException(java.io.IOException) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 60 with SubCommandException

use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DeleteKvConfigCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        // 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");
    } 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)

Aggregations

SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)88 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)76 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)22 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)16 MQClientException (org.apache.rocketmq.client.exception.MQClientException)16 Set (java.util.Set)14 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)12 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)8 Connection (org.apache.rocketmq.common.protocol.body.Connection)8 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)8 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)8 Date (java.util.Date)6 Entry (java.util.Map.Entry)6 Properties (java.util.Properties)6 DefaultMQPullConsumer (org.apache.rocketmq.client.consumer.DefaultMQPullConsumer)6 PullResult (org.apache.rocketmq.client.consumer.PullResult)6 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)6