use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class TopicRouteSubCommand 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();
String topic = commandLine.getOptionValue('t').trim();
TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
String json = topicRouteData.toJson(true);
System.out.printf("%s%n", json);
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class QueryConsumeQueueCommand method execute.
@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 topic = commandLine.getOptionValue("t").trim();
int queueId = Integer.valueOf(commandLine.getOptionValue("q").trim());
long index = Long.valueOf(commandLine.getOptionValue("i").trim());
int count = Integer.valueOf(commandLine.getOptionValue("c", "10").trim());
String broker = null;
if (commandLine.hasOption("b")) {
broker = commandLine.getOptionValue("b").trim();
}
String consumerGroup = null;
if (commandLine.hasOption("g")) {
consumerGroup = commandLine.getOptionValue("g").trim();
}
if (broker == null || broker == "") {
TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
if (topicRouteData == null || topicRouteData.getBrokerDatas() == null || topicRouteData.getBrokerDatas().isEmpty()) {
throw new Exception("No topic route data!");
}
broker = topicRouteData.getBrokerDatas().get(0).getBrokerAddrs().get(0L);
}
QueryConsumeQueueResponseBody queryConsumeQueueResponseBody = defaultMQAdminExt.queryConsumeQueue(broker, topic, queueId, index, count, consumerGroup);
if (queryConsumeQueueResponseBody.getSubscriptionData() != null) {
System.out.printf("Subscription data: \n%s\n", JSON.toJSONString(queryConsumeQueueResponseBody.getSubscriptionData(), true));
System.out.print("======================================\n");
}
if (queryConsumeQueueResponseBody.getFilterData() != null) {
System.out.printf("Filter data: \n%s\n", queryConsumeQueueResponseBody.getFilterData());
System.out.print("======================================\n");
}
System.out.printf("Queue data: \nmax: %d, min: %d\n", queryConsumeQueueResponseBody.getMaxQueueIndex(), queryConsumeQueueResponseBody.getMinQueueIndex());
System.out.print("======================================\n");
if (queryConsumeQueueResponseBody.getQueueData() != null) {
long i = index;
for (ConsumeQueueData queueData : queryConsumeQueueResponseBody.getQueueData()) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("idx: " + i + "\n");
stringBuilder.append(queueData.toString() + "\n");
stringBuilder.append("======================================\n");
System.out.print(stringBuilder.toString());
i++;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
defaultMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq by apache.
the class DefaultMQAdminExtTest method testExamineTopicRouteInfo.
@Test
public void testExamineTopicRouteInfo() throws RemotingException, MQClientException, InterruptedException {
TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo("UnitTest");
assertThat(topicRouteData.getBrokerDatas().get(0).getBrokerName()).isEqualTo("default-broker");
assertThat(topicRouteData.getBrokerDatas().get(0).getCluster()).isEqualTo("default-cluster");
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq by apache.
the class QueryConsumeQueueCommand method execute.
@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 topic = commandLine.getOptionValue("t").trim();
int queueId = Integer.valueOf(commandLine.getOptionValue("q").trim());
long index = Long.valueOf(commandLine.getOptionValue("i").trim());
int count = Integer.valueOf(commandLine.getOptionValue("c", "10").trim());
String broker = null;
if (commandLine.hasOption("b")) {
broker = commandLine.getOptionValue("b").trim();
}
String consumerGroup = null;
if (commandLine.hasOption("g")) {
consumerGroup = commandLine.getOptionValue("g").trim();
}
if (broker == null || broker == "") {
TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
if (topicRouteData == null || topicRouteData.getBrokerDatas() == null || topicRouteData.getBrokerDatas().isEmpty()) {
throw new Exception("No topic route data!");
}
broker = topicRouteData.getBrokerDatas().get(0).getBrokerAddrs().get(0L);
}
QueryConsumeQueueResponseBody queryConsumeQueueResponseBody = defaultMQAdminExt.queryConsumeQueue(broker, topic, queueId, index, count, consumerGroup);
if (queryConsumeQueueResponseBody.getSubscriptionData() != null) {
System.out.printf("Subscription data: \n%s\n", JSON.toJSONString(queryConsumeQueueResponseBody.getSubscriptionData(), true));
System.out.print("======================================\n");
}
if (queryConsumeQueueResponseBody.getFilterData() != null) {
System.out.printf("Filter data: \n%s\n", queryConsumeQueueResponseBody.getFilterData());
System.out.print("======================================\n");
}
System.out.printf("Queue data: \nmax: %d, min: %d\n", queryConsumeQueueResponseBody.getMaxQueueIndex(), queryConsumeQueueResponseBody.getMinQueueIndex());
System.out.print("======================================\n");
if (queryConsumeQueueResponseBody.getQueueData() != null) {
long i = index;
for (ConsumeQueueData queueData : queryConsumeQueueResponseBody.getQueueData()) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("idx: " + i + "\n");
stringBuilder.append(queueData.toString() + "\n");
stringBuilder.append("======================================\n");
System.out.print(stringBuilder.toString());
i++;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
defaultMQAdminExt.shutdown();
}
}
use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq by apache.
the class StatsAllSubCommand method printTopicDetail.
public static void printTopicDetail(final DefaultMQAdminExt admin, final String topic, final boolean activeTopic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
TopicRouteData topicRouteData = admin.examineTopicRouteInfo(topic);
GroupList groupList = admin.queryTopicConsumeByWho(topic);
double inTPS = 0;
long inMsgCntToday = 0;
for (BrokerData bd : topicRouteData.getBrokerDatas()) {
String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
if (masterAddr != null) {
try {
BrokerStatsData bsd = admin.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic);
inTPS += bsd.getStatsMinute().getTps();
inMsgCntToday += compute24HourSum(bsd);
} catch (Exception e) {
}
}
}
if (groupList != null && !groupList.getGroupList().isEmpty()) {
for (String group : groupList.getGroupList()) {
double outTPS = 0;
long outMsgCntToday = 0;
for (BrokerData bd : topicRouteData.getBrokerDatas()) {
String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
if (masterAddr != null) {
try {
String statsKey = String.format("%s@%s", topic, group);
BrokerStatsData bsd = admin.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey);
outTPS += bsd.getStatsMinute().getTps();
outMsgCntToday += compute24HourSum(bsd);
} catch (Exception e) {
}
}
}
long accumulate = 0;
try {
ConsumeStats consumeStats = admin.examineConsumeStats(group, topic);
if (consumeStats != null) {
accumulate = consumeStats.computeTotalDiff();
if (accumulate < 0) {
accumulate = 0;
}
}
} catch (Exception e) {
}
if (!activeTopic || (inMsgCntToday > 0) || (outMsgCntToday > 0)) {
System.out.printf("%-32s %-32s %12d %11.2f %11.2f %14d %14d%n", UtilAll.frontStringAtLeast(topic, 32), UtilAll.frontStringAtLeast(group, 32), accumulate, inTPS, outTPS, inMsgCntToday, outMsgCntToday);
}
}
} else {
if (!activeTopic || (inMsgCntToday > 0)) {
System.out.printf("%-32s %-32s %12d %11.2f %11s %14d %14s%n", UtilAll.frontStringAtLeast(topic, 32), "", 0, inTPS, "", inMsgCntToday, "NO_CONSUMER");
}
}
}
Aggregations