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