use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class DeleteTopicSubCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
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) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
adminExt.shutdown();
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class TopicListSubCommand method execute.
@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();
if (commandLine.hasOption('c')) {
ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
System.out.printf("%-20s %-48s %-48s%n", "#Cluster Name", "#Topic", "#Consumer Group");
TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
for (String topic : topicList.getTopicList()) {
if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
continue;
}
String clusterName = "";
GroupList groupList = new GroupList();
try {
clusterName = this.findTopicBelongToWhichCluster(topic, clusterInfo, defaultMQAdminExt);
groupList = defaultMQAdminExt.queryTopicConsumeByWho(topic);
} catch (Exception e) {
}
if (null == groupList || groupList.getGroupList().isEmpty()) {
groupList = new GroupList();
groupList.getGroupList().add("");
}
for (String group : groupList.getGroupList()) {
System.out.printf("%-20s %-48s %-48s%n", UtilAll.frontStringAtLeast(clusterName, 20), UtilAll.frontStringAtLeast(topic, 48), UtilAll.frontStringAtLeast(group, 48));
}
}
} else {
TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
for (String topic : topicList.getTopicList()) {
System.out.printf("%s%n", topic);
}
}
} 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 by apache.
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 by apache.
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();
}
}
use of org.apache.rocketmq.tools.command.SubCommandException in project rocketmq by apache.
the class GetNamesrvConfigCommand method execute.
@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 {
// servers
String servers = commandLine.getOptionValue('n');
List<String> serverList = null;
if (servers != null && servers.length() > 0) {
String[] serverArray = servers.trim().split(";");
if (serverArray.length > 0) {
serverList = Arrays.asList(serverArray);
}
}
defaultMQAdminExt.start();
Map<String, Properties> nameServerConfigs = defaultMQAdminExt.getNameServerConfig(serverList);
for (String server : nameServerConfigs.keySet()) {
System.out.printf("============%s============\n", server);
for (Object key : nameServerConfigs.get(server).keySet()) {
System.out.printf("%-50s= %s\n", key, nameServerConfigs.get(server).get(key));
}
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
Aggregations