Java Code Examples for org.apache.rocketmq.tools.admin.DefaultMQAdminExt#shutdown()
The following examples show how to use
org.apache.rocketmq.tools.admin.DefaultMQAdminExt#shutdown() .
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: 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 2
Source File: CleanExpiredCQSubCommand.java From rocketmq with Apache License 2.0 | 6 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { boolean result = false; defaultMQAdminExt.start(); if (commandLine.hasOption('b')) { String addr = commandLine.getOptionValue('b').trim(); result = defaultMQAdminExt.cleanExpiredConsumerQueueByAddr(addr); } else { String cluster = commandLine.getOptionValue('c'); if (null != cluster) cluster = cluster.trim(); result = defaultMQAdminExt.cleanExpiredConsumerQueue(cluster); } System.out.printf(result ? "success" : "false"); } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 3
Source File: UpdateKvConfigCommand.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
@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(); // key name String value = commandLine.getOptionValue('v').trim(); defaultMQAdminExt.start(); defaultMQAdminExt.createAndUpdateKvConfig(namespace, key, value); System.out.printf("create or update kv config to namespace success.%n"); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 4
Source File: QueryMsgByKeySubCommand.java From rocketmq-read with Apache License 2.0 | 6 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { final String topic = commandLine.getOptionValue('t').trim(); final String key = commandLine.getOptionValue('k').trim(); this.queryByKey(defaultMQAdminExt, topic, key); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 5
Source File: QueryMsgByUniqueKeySubCommand.java From rocketmq_trans_message with Apache License 2.0 | 6 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(); 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) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 6
Source File: TopicClusterSubCommand.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())); String topic = commandLine.getOptionValue('t').trim(); try { defaultMQAdminExt.start(); Set<String> clusters = defaultMQAdminExt.getTopicClusterList(topic); for (String value : clusters) { System.out.printf("%s%n", value); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 7
Source File: CleanUnusedTopicCommand.java From rocketmq with Apache License 2.0 | 6 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { boolean result = false; defaultMQAdminExt.start(); if (commandLine.hasOption('b')) { String addr = commandLine.getOptionValue('b').trim(); result = defaultMQAdminExt.cleanUnusedTopicByAddr(addr); } else { String cluster = commandLine.getOptionValue('c'); if (null != cluster) cluster = cluster.trim(); result = defaultMQAdminExt.cleanUnusedTopicByAddr(cluster); } System.out.printf(result ? "success" : "false"); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 8
Source File: TopicClusterSubCommand.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())); String topic = commandLine.getOptionValue('t').trim(); try { defaultMQAdminExt.start(); Set<String> clusters = defaultMQAdminExt.getTopicClusterList(topic); for (String value : clusters) { System.out.printf("%s%n", value); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 9
Source File: UpdateNamesrvConfigCommand.java From rocketmq with Apache License 2.0 | 5 votes |
@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 { // key name String key = commandLine.getOptionValue('k').trim(); // key name String value = commandLine.getOptionValue('v').trim(); Properties properties = new Properties(); properties.put(key, value); // 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(); defaultMQAdminExt.updateNameServerConfig(properties, serverList); System.out.printf("update name server config success!%s\n%s : %s\n", serverList == null ? "" : serverList, key, value); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 10
Source File: MQAdmin.java From DDMQ with Apache License 2.0 | 5 votes |
public static ClusterInfo getCluster(String nameSrvAddr) { DefaultMQAdminExt mqAdminExt = new DefaultMQAdminExt(); mqAdminExt.setNamesrvAddr(nameSrvAddr); ClusterInfo clusterInfo = null; try { mqAdminExt.start(); clusterInfo = mqAdminExt.examineBrokerClusterInfo(); } catch (Exception e) { e.printStackTrace(); } mqAdminExt.shutdown(); return clusterInfo; }
Example 11
Source File: EnableBrokerRoleSwitchCommand.java From DDMQ with Apache License 2.0 | 5 votes |
@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 { // cluster name String clusterName = commandLine.getOptionValue('c').trim(); // broker name String brokerName = commandLine.getOptionValue('b').trim(); // 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(); defaultMQAdminExt.enableBrokerRoleSwitch(clusterName, brokerName, serverList); System.out.printf("enable broker role switch success!%s\n%s : %s\n", serverList == null ? "" : serverList, clusterName, brokerName); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 12
Source File: DeleteTopicSubCommand.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 { String topic = commandLine.getOptionValue('t').trim(); adminExt.start(); if (commandLine.hasOption('c')) { String clusterName = commandLine.getOptionValue('c').trim(); deleteTopic(adminExt, clusterName, topic); return; } else if (commandLine.hasOption("b")) { String brokerAddrs = commandLine.getOptionValue('b').trim(); String[] brokerArr = brokerAddrs.split(";"); if (brokerArr.length <= 0) { throw new IllegalArgumentException("not broker"); } Set<String> brokerSet = new HashSet<>(); Collections.addAll(brokerSet, brokerArr); deleteTopicByBroker(adminExt, brokerSet, topic); return; } ServerUtil.printCommandLineHelp("mqadmin " + this.commandName(), options); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { adminExt.shutdown(); } }
Example 13
Source File: UpdateNamesrvConfigCommand.java From DDMQ with Apache License 2.0 | 5 votes |
@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 { // key name String key = commandLine.getOptionValue('k').trim(); // key name String value = commandLine.getOptionValue('v').trim(); Properties properties = new Properties(); properties.put(key, value); // 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(); defaultMQAdminExt.updateNameServerConfig(properties, serverList); System.out.printf("update name server config success!%s\n%s : %s\n", serverList == null ? "" : serverList, key, value); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 14
Source File: ClusterListSubCommand.java From DDMQ with Apache License 2.0 | 5 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())); long printInterval = 1; boolean enableInterval = commandLine.hasOption('i'); if (enableInterval) { printInterval = Long.parseLong(commandLine.getOptionValue('i')) * 1000; } try { defaultMQAdminExt.start(); long i = 0; do { if (i++ > 0) { Thread.sleep(printInterval); } if (commandLine.hasOption('m')) { this.printClusterMoreStats(defaultMQAdminExt); } else { this.printClusterBaseInfo(defaultMQAdminExt); } } while (enableInterval); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 15
Source File: UpdateNamesrvConfigCommand.java From DDMQ with Apache License 2.0 | 5 votes |
@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 { // key name String key = commandLine.getOptionValue('k').trim(); // key name String value = commandLine.getOptionValue('v').trim(); Properties properties = new Properties(); properties.put(key, value); // 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(); defaultMQAdminExt.updateNameServerConfig(properties, serverList); System.out.printf("update name server config success!%s\n%s : %s\n", serverList == null ? "" : serverList, key, value); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 16
Source File: AllocateMQSubCommand.java From rocketmq-read 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 17
Source File: ProducerConnectionSubCommand.java From rocketmq with Apache License 2.0 | 5 votes |
@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(); String group = commandLine.getOptionValue('g').trim(); String topic = commandLine.getOptionValue('t').trim(); ProducerConnection pc = defaultMQAdminExt.examineProducerConnectionInfo(group, topic); int i = 1; for (Connection conn : pc.getConnectionSet()) { System.out.printf("%04d %-32s %-22s %-8s %s%n", i++, conn.getClientId(), conn.getClientAddr(), conn.getLanguage(), MQVersion.getVersionDesc(conn.getVersion()) ); } } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 18
Source File: GetBrokerConfigCommand.java From rocketmq with Apache License 2.0 | 4 votes |
@Override public void execute(final CommandLine commandLine, final Options options, final RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { if (commandLine.hasOption('b')) { String brokerAddr = commandLine.getOptionValue('b').trim(); defaultMQAdminExt.start(); getAndPrint(defaultMQAdminExt, String.format("============%s============\n", brokerAddr), brokerAddr); } else if (commandLine.hasOption('c')) { String clusterName = commandLine.getOptionValue('c').trim(); defaultMQAdminExt.start(); Map<String, List<String>> masterAndSlaveMap = CommandUtil.fetchMasterAndSlaveDistinguish(defaultMQAdminExt, clusterName); for (String masterAddr : masterAndSlaveMap.keySet()) { getAndPrint( defaultMQAdminExt, String.format("============Master: %s============\n", masterAddr), masterAddr ); for (String slaveAddr : masterAndSlaveMap.get(masterAddr)) { getAndPrint( defaultMQAdminExt, String.format("============My Master: %s=====Slave: %s============\n", masterAddr, slaveAddr), slaveAddr ); } } } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 19
Source File: ConsumerConnectionSubCommand.java From DDMQ with Apache License 2.0 | 4 votes |
@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(); String group = commandLine.getOptionValue('g').trim(); ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(group); int i = 1; for (Connection conn : cc.getConnectionSet()) { System.out.printf("%03d %-32s %-22s %-8s %s%n", i++, conn.getClientId(), conn.getClientAddr(), conn.getLanguage(), MQVersion.getVersionDesc(conn.getVersion()) ); } System.out.printf("%nBelow is subscription:"); Iterator<Entry<String, SubscriptionData>> it = cc.getSubscriptionTable().entrySet().iterator(); i = 1; while (it.hasNext()) { Entry<String, SubscriptionData> entry = it.next(); SubscriptionData sd = entry.getValue(); System.out.printf("%03d Topic: %-40s SubExpression: %s%n", i++, sd.getTopic(), sd.getSubString() ); } System.out.printf(""); System.out.printf("ConsumeType: %s%n", cc.getConsumeType()); System.out.printf("MessageModel: %s%n", cc.getMessageModel()); System.out.printf("ConsumeFromWhere: %s%n", cc.getConsumeFromWhere()); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 20
Source File: GetConsumerStatusCommand.java From rocketmq-read with Apache License 2.0 | 4 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { 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"); for (Map.Entry<String, Map<MessageQueue, Long>> entry : consumerStatusTable.entrySet()) { String clientId = entry.getKey(); Map<MessageQueue, Long> mqTable = entry.getValue(); for (Map.Entry<MessageQueue, Long> entry1 : mqTable.entrySet()) { MessageQueue mq = entry1.getKey(); System.out.printf("%-50s %-15s %-15d %-20d%n", UtilAll.frontStringAtLeast(clientId, 50), mq.getBrokerName(), mq.getQueueId(), mqTable.get(mq)); } } } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }