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);
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations