Java Code Examples for org.apache.rocketmq.tools.admin.DefaultMQAdminExt#examineTopicRouteInfo()
The following examples show how to use
org.apache.rocketmq.tools.admin.DefaultMQAdminExt#examineTopicRouteInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopicListSubCommand.java From rocketmq with Apache License 2.0 | 6 votes |
private String findTopicBelongToWhichCluster(final String topic, final ClusterInfo clusterInfo, final DefaultMQAdminExt defaultMQAdminExt) throws RemotingException, MQClientException, InterruptedException { TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic); BrokerData brokerData = topicRouteData.getBrokerDatas().get(0); String brokerName = brokerData.getBrokerName(); Iterator<Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator(); while (it.hasNext()) { Entry<String, Set<String>> next = it.next(); if (next.getValue().contains(brokerName)) { return next.getKey(); } } return null; }
Example 2
Source File: TopicRouteSubCommand.java From rocketmq with Apache License 2.0 | 6 votes |
@Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { 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) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 3
Source File: TopicRouteSubCommand.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
@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(); } }
Example 4
Source File: TopicListSubCommand.java From DDMQ with Apache License 2.0 | 6 votes |
private String findTopicBelongToWhichCluster(final String topic, final ClusterInfo clusterInfo, final DefaultMQAdminExt defaultMQAdminExt) throws RemotingException, MQClientException, InterruptedException { TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic); BrokerData brokerData = topicRouteData.getBrokerDatas().get(0); String brokerName = brokerData.getBrokerName(); Iterator<Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator(); while (it.hasNext()) { Entry<String, Set<String>> next = it.next(); if (next.getValue().contains(brokerName)) { return next.getKey(); } } return null; }
Example 5
Source File: TopicRouteSubCommand.java From DDMQ with Apache License 2.0 | 6 votes |
@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(); } }
Example 6
Source File: TopicRouteSubCommand.java From rocketmq with Apache License 2.0 | 6 votes |
@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(); } }
Example 7
Source File: TopicRouteSubCommand.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
@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(); } }
Example 8
Source File: RmqAdminServiceImpl.java From DDMQ with Apache License 2.0 | 6 votes |
@Override public Message queryLatestMessage(String nameServer, String topic) throws Exception { DefaultMQAdminExt defaultMQAdminExt = getMQAdminExt(nameServer); TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic); if (topicRouteData == null) { throw new MqException("[RMQ] topic<" + topic + "> route info is null"); } List<QueueData> queueDatas = topicRouteData.getQueueDatas(); Collections.shuffle(queueDatas); for (QueueData queueData : queueDatas) { for (int i = 0; i < queueData.getReadQueueNums(); i++) { long maxOffsets = defaultMQAdminExt.maxOffset(new MessageQueue(topic, queueData.getBrokerName(), i)); if (maxOffsets <= 0) { continue; } Message msg = queryMessageByOffset(nameServer, topic, queueData.getBrokerName(), i, maxOffsets - 1); if (msg != null) { return msg; } } } throw new MqException("[RMQ] fetch rmq latestmsg error, not exist"); }
Example 9
Source File: TopicRouteSubCommand.java From rocketmq_trans_message with Apache License 2.0 | 6 votes |
@Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { 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) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 10
Source File: CloneGroupOffsetCommand.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { String srcGroup = commandLine.getOptionValue("s").trim(); String destGroup = commandLine.getOptionValue("d").trim(); String topic = commandLine.getOptionValue("t").trim(); DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName("admin-" + Long.toString(System.currentTimeMillis())); try { defaultMQAdminExt.start(); ConsumeStats consumeStats = defaultMQAdminExt.examineConsumeStats(srcGroup); Set<MessageQueue> mqs = consumeStats.getOffsetTable().keySet(); if (!mqs.isEmpty()) { TopicRouteData topicRoute = defaultMQAdminExt.examineTopicRouteInfo(topic); for (MessageQueue mq : mqs) { String addr = null; for (BrokerData brokerData : topicRoute.getBrokerDatas()) { if (brokerData.getBrokerName().equals(mq.getBrokerName())) { addr = brokerData.selectBrokerAddr(); break; } } long offset = consumeStats.getOffsetTable().get(mq).getBrokerOffset(); if (offset >= 0) { defaultMQAdminExt.updateConsumeOffset(addr, destGroup, mq, offset); } } } System.out.printf("clone group offset success. srcGroup[%s], destGroup=[%s], topic[%s]", srcGroup, destGroup, topic); } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 11
Source File: AllocateMQSubCommand.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook); adminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { adminExt.start(); String topic = commandLine.getOptionValue('t').trim(); String ips = commandLine.getOptionValue('i').trim(); final String[] split = ips.split(","); final List<String> ipList = new LinkedList<String>(); for (String ip : split) { ipList.add(ip); } final TopicRouteData topicRouteData = adminExt.examineTopicRouteInfo(topic); final Set<MessageQueue> mqs = MQClientInstance.topicRouteData2TopicSubscribeInfo(topic, topicRouteData); final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely(); RebalanceResult rr = new RebalanceResult(); for (String i : ipList) { final List<MessageQueue> mqResult = averagely.allocate("aa", i, new ArrayList<MessageQueue>(mqs), ipList); rr.getResult().put(i, mqResult); } final String json = RemotingSerializable.toJson(rr, false); System.out.printf("%s%n", json); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { adminExt.shutdown(); } }
Example 12
Source File: AllocateMQSubCommand.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook); adminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { adminExt.start(); String topic = commandLine.getOptionValue('t').trim(); String ips = commandLine.getOptionValue('i').trim(); final String[] split = ips.split(","); final List<String> ipList = new LinkedList<String>(); for (String ip : split) { ipList.add(ip); } final TopicRouteData topicRouteData = adminExt.examineTopicRouteInfo(topic); final Set<MessageQueue> mqs = MQClientInstance.topicRouteData2TopicSubscribeInfo(topic, topicRouteData); final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely(); RebalanceResult rr = new RebalanceResult(); for (String i : ipList) { final List<MessageQueue> mqResult = averagely.allocate("aa", i, new ArrayList<MessageQueue>(mqs), ipList); rr.getResult().put(i, mqResult); } final String json = RemotingSerializable.toJson(rr, false); System.out.printf("%s%n", json); } catch (Exception e) { e.printStackTrace(); } finally { adminExt.shutdown(); } }
Example 13
Source File: AllocateMQSubCommand.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook); adminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { adminExt.start(); String topic = commandLine.getOptionValue('t').trim(); String ips = commandLine.getOptionValue('i').trim(); final String[] split = ips.split(","); final List<String> ipList = new LinkedList<String>(); for (String ip : split) { ipList.add(ip); } final TopicRouteData topicRouteData = adminExt.examineTopicRouteInfo(topic); final Set<MessageQueue> mqs = MQClientInstance.topicRouteData2TopicSubscribeInfo(topic, topicRouteData); final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely(); RebalanceResult rr = new RebalanceResult(); for (String i : ipList) { final List<MessageQueue> mqResult = averagely.allocate("aa", i, new ArrayList<MessageQueue>(mqs), ipList); rr.getResult().put(i, mqResult); } final String json = RemotingSerializable.toJson(rr, false); System.out.printf("%s%n", json); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { adminExt.shutdown(); } }
Example 14
Source File: CloneGroupOffsetCommand.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { String srcGroup = commandLine.getOptionValue("s").trim(); String destGroup = commandLine.getOptionValue("d").trim(); String topic = commandLine.getOptionValue("t").trim(); DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName("admin-" + Long.toString(System.currentTimeMillis())); try { defaultMQAdminExt.start(); ConsumeStats consumeStats = defaultMQAdminExt.examineConsumeStats(srcGroup); Set<MessageQueue> mqs = consumeStats.getOffsetTable().keySet(); if (!mqs.isEmpty()) { TopicRouteData topicRoute = defaultMQAdminExt.examineTopicRouteInfo(topic); for (MessageQueue mq : mqs) { String addr = null; for (BrokerData brokerData : topicRoute.getBrokerDatas()) { if (brokerData.getBrokerName().equals(mq.getBrokerName())) { addr = brokerData.selectBrokerAddr(); break; } } long offset = consumeStats.getOffsetTable().get(mq).getBrokerOffset(); if (offset >= 0) { defaultMQAdminExt.updateConsumeOffset(addr, destGroup, mq, offset); } } } System.out.printf("clone group offset success. srcGroup[%s], destGroup=[%s], topic[%s]", srcGroup, destGroup, topic); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 15
Source File: AllocateMQSubCommand.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook); adminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { adminExt.start(); String topic = commandLine.getOptionValue('t').trim(); String ips = commandLine.getOptionValue('i').trim(); final String[] split = ips.split(","); final List<String> ipList = new LinkedList<String>(); for (String ip : split) { ipList.add(ip); } final TopicRouteData topicRouteData = adminExt.examineTopicRouteInfo(topic); final Set<MessageQueue> mqs = MQClientInstance.topicRouteData2TopicSubscribeInfo(topic, topicRouteData); final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely(); RebalanceResult rr = new RebalanceResult(); for (String i : ipList) { final List<MessageQueue> mqResult = averagely.allocate("aa", i, new ArrayList<MessageQueue>(mqs), ipList); rr.getResult().put(i, mqResult); } final String json = RemotingSerializable.toJson(rr, false); System.out.printf("%s%n", json); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { adminExt.shutdown(); } }
Example 16
Source File: Utils.java From DDMQ with Apache License 2.0 | 5 votes |
public static boolean isBrokerTopicWritable(String cluster, String nameSvr, String address/* broker Address */) { try { DefaultMQAdminExt adminExt = getMQAdminExt(nameSvr, cluster); String brokerPermission = adminExt.getBrokerConfig(address).getProperty("brokerPermission"); if (!PermName.isWriteable(Integer.parseInt(brokerPermission))) { logger.info("skip send because of broker brokerPermission={}. cluster={}, namesvr={}, address={}", brokerPermission, cluster, nameSvr, address); return false; } TopicRouteData topicRouteInfo = adminExt.examineTopicRouteInfo("SELF_TEST_TOPIC"); String brokerName = null; for (BrokerData brokerData : topicRouteInfo.getBrokerDatas()) { if (StringUtils.equals(brokerData.getBrokerAddrs().get(0L), address)) { brokerName = brokerData.getBrokerName(); break; } } if (brokerName != null) { for (QueueData queueData : topicRouteInfo.getQueueDatas()) { if (StringUtils.equals(queueData.getBrokerName(), brokerName)) { if (queueData.getWriteQueueNums() == 0 || !PermName.isWriteable(queueData.getPerm())) { logger.info("skip send because of queue.Permission={},queue.writeQNuum={}. cluster={}, namesvr={}, address={}", queueData.getPerm(), queueData.getWriteQueueNums(), cluster, nameSvr, address); return false; } break; } } } } catch (Exception e) { logger.error("exception in isBrokerTopicWritable, cluster={}, namesvr={}, address={}", cluster, nameSvr, address, e); } return true; }
Example 17
Source File: QueryConsumeQueueCommand.java From rocketmq with Apache License 2.0 | 4 votes |
@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(); } }
Example 18
Source File: QueryConsumeQueueCommand.java From rocketmq-4.3.0 with Apache License 2.0 | 4 votes |
@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(); } }
Example 19
Source File: QueryConsumeQueueCommand.java From DDMQ with Apache License 2.0 | 4 votes |
@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(); } }
Example 20
Source File: QueryConsumeQueueCommand.java From DDMQ with Apache License 2.0 | 4 votes |
@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(); } }