Java Code Examples for com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt#start()
The following examples show how to use
com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt#start() .
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: DeleteTopicSubCommand.java From RocketMQ-Master-analyze with Apache License 2.0 | 6 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { 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) { e.printStackTrace(); } finally { adminExt.shutdown(); } }
Example 2
Source File: DeleteKvConfigCommand.java From RocketMQ-Master-analyze 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 { // 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"); return; } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 3
Source File: TopicRouteSubCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.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.println(json); } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 4
Source File: ConnectionService.java From rocketmq with Apache License 2.0 | 6 votes |
@CmdTrace(cmdClazz = ProducerConnectionSubCommand.class) public ProducerConnection getProducerConnection(String group, String topicName) throws Throwable { Throwable t = null; DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt(); try { defaultMQAdminExt.start(); ProducerConnection pc = defaultMQAdminExt.examineProducerConnectionInfo(group, topicName); return pc; } catch (Throwable e) { logger.error(e.getMessage(), e); t = e; } finally { shutdownDefaultMQAdminExt(defaultMQAdminExt); } throw t; }
Example 5
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.println(value); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 6
Source File: DeleteKvConfigCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.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 { // 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"); return; } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 7
Source File: MQAdminInstance.java From rocket-console with Apache License 2.0 | 5 votes |
public static void initMQAdminInstance() throws MQClientException { Integer nowCount = initCounter.get(); if (nowCount == null) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); defaultMQAdminExt.start(); mqAdminExtThreadLocal.set(defaultMQAdminExt); initCounter.set(1); } else { initCounter.set(nowCount + 1); } }
Example 8
Source File: ClusterListSubCommand.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { 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(); do { if (commandLine.hasOption('m')) { this.printClusterMoreStats(defaultMQAdminExt); } else { this.printClusterBaseInfo(defaultMQAdminExt); } Thread.sleep(printInterval); System.out.println(""); } while (enableInterval); } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 9
Source File: BrokerService.java From rocketmq with Apache License 2.0 | 5 votes |
@CmdTrace(cmdClazz = UpdateBrokerConfigSubCommand.class) public boolean updateBrokerConfig(String brokerAddr, String clusterName, String key, String value) throws Throwable { Throwable t = null; DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt(); try { Properties properties = new Properties(); properties.put(key, value); if (StringUtils.isNotBlank(brokerAddr)) { defaultMQAdminExt.start(); defaultMQAdminExt.updateBrokerConfig(brokerAddr, properties); return true; } else if (StringUtils.isNotBlank(clusterName)) { defaultMQAdminExt.start(); Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); for (String tempBrokerAddr : masterSet) { defaultMQAdminExt.updateBrokerConfig(tempBrokerAddr, properties); } return true; } else { throw new IllegalStateException("brokerAddr or clusterName can not be all blank"); } } catch (Throwable e) { logger.error(e.getMessage(), e); t = e; } finally { shutdownDefaultMQAdminExt(defaultMQAdminExt); } throw t; }
Example 10
Source File: ClusterListSubCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
@Override public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) { 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(); do { if (commandLine.hasOption('m')) { this.printClusterMoreStats(defaultMQAdminExt); } else { this.printClusterBaseInfo(defaultMQAdminExt); } Thread.sleep(printInterval); System.out.println(""); } while (enableInterval); } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 11
Source File: QueryMsgByIdSubCommand.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 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(); 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, msgId); System.out.println(result); } else { queryById(defaultMQAdminExt, msgId); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 12
Source File: TopicService.java From rocketmq with Apache License 2.0 | 5 votes |
@CmdTrace(cmdClazz = DeleteTopicSubCommand.class) public boolean delete(String topicName, String clusterName) throws Throwable { Throwable t = null; DefaultMQAdminExt adminExt = getDefaultMQAdminExt(); try { if (StringUtils.isNotBlank(clusterName)) { adminExt.start(); Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(adminExt, clusterName); adminExt.deleteTopicInBroker(masterSet, topicName); Set<String> nameServerSet = null; if (StringUtils.isNotBlank(configureInitializer.getNamesrvAddr())) { String[] ns = configureInitializer.getNamesrvAddr().split(";"); nameServerSet = new HashSet<String>(Arrays.asList(ns)); } adminExt.deleteTopicInNameServer(nameServerSet, topicName); return true; } else { throw new IllegalStateException("clusterName is blank"); } } catch (Throwable e) { logger.error(e.getMessage(), e); t = e; } finally { shutdownDefaultMQAdminExt(adminExt); } throw t; }
Example 13
Source File: QueryMsgByKeySubCommand.java From rocketmq with Apache License 2.0 | 5 votes |
void queryByKey(final DefaultMQAdminExt admin, final String topic, final String key) throws MQClientException, InterruptedException { admin.start(); QueryResult queryResult = admin.queryMessage(topic, key, 64, 0, Long.MAX_VALUE); System.out.printf("%-50s %4s %40s%n",// "#Message ID",// "#QID",// "#Offset"); for (MessageExt msg : queryResult.getMessageList()) { System.out.printf("%-50s %4d %40d%n", msg.getMsgId(), msg.getQueueId(), msg.getQueueOffset()); } }
Example 14
Source File: CloneGroupOffsetCommand.java From rocketmq 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 != null && !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 15
Source File: NamesrvService.java From rocketmq with Apache License 2.0 | 5 votes |
@CmdTrace(cmdClazz = GetProjectGroupCommand.class) public String getProjectGroup(String ip, String project) throws Throwable { Throwable t = null; DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt(); try { if (StringUtils.isNotBlank(ip)) { defaultMQAdminExt.start(); String projectInfo = defaultMQAdminExt.getProjectGroupByIp(ip); return projectInfo; } else if (StringUtils.isNotBlank(project)) { defaultMQAdminExt.start(); String ips = defaultMQAdminExt.getIpsByProjectGroup(project); return ips; } else { throw new IllegalStateException("project or ip can not be all blank!"); } } catch (Throwable e) { logger.error(e.getMessage(), e); t = e; } finally { shutdownDefaultMQAdminExt(defaultMQAdminExt); } throw t; }
Example 16
Source File: QueryMsgByKeySubCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
void queryByKey(final DefaultMQAdminExt admin, final String topic, final String key) throws MQClientException, InterruptedException { admin.start(); QueryResult queryResult = admin.queryMessage(topic, key, 64, 0, Long.MAX_VALUE); System.out.printf("%-50s %4s %40s\n",// "#Message ID",// "#QID",// "#Offset"); for (MessageExt msg : queryResult.getMessageList()) { System.out.printf("%-50s %4d %40d\n", msg.getMsgId(), msg.getQueueId(), msg.getQueueOffset()); } }
Example 17
Source File: QueryMsgByUniqueKeySubCommand.java From rocketmq with Apache License 2.0 | 5 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.println(result); } else { queryById(defaultMQAdminExt,topic, msgId); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 18
Source File: MessageService.java From rocketmq with Apache License 2.0 | 4 votes |
@CmdTrace(cmdClazz = QueryMsgByIdSubCommand.class) public Table queryMsgById(String msgId) throws Throwable { Throwable t = null; Map<String, String> map = new LinkedHashMap<String, String>(); DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt(); try { defaultMQAdminExt.start(); MessageExt msg = defaultMQAdminExt.viewMessage(msgId); String bodyTmpFilePath = createBodyFile(msg); // System.out.printf("%-20s %s\n",// // "Topic:",// // msg.getTopic()// // ); map.put("Topic", msg.getTopic()); // System.out.printf("%-20s %s\n",// // "Tags:",// // "[" + msg.getTags() + "]"// // ); map.put("Tags", "[" + msg.getTags() + "]"); // System.out.printf("%-20s %s\n",// // "Keys:",// // "[" + msg.getKeys() + "]"// // ); map.put("Keys", "[" + msg.getKeys() + "]"); // System.out.printf("%-20s %d\n",// // "Queue ID:",// // msg.getQueueId()// // ); map.put("Queue ID", String.valueOf(msg.getQueueId())); // System.out.printf("%-20s %d\n",// // "Queue Offset:",// // msg.getQueueOffset()// // ); map.put("Queue Offset:", String.valueOf(msg.getQueueOffset())); // System.out.printf("%-20s %d\n",// // "CommitLog Offset:",// // msg.getCommitLogOffset()// // ); map.put("CommitLog Offset:", String.valueOf(msg.getCommitLogOffset())); // System.out.printf("%-20s %s\n",// // "Born Timestamp:",// // UtilAll.timeMillisToHumanString2(msg.getBornTimestamp())// // ); map.put("Born Timestamp:", UtilAll.timeMillisToHumanString2(msg.getBornTimestamp())); // System.out.printf("%-20s %s\n",// // "Store Timestamp:",// // UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp())// // ); map.put("Store Timestamp:", UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp())); // System.out.printf("%-20s %s\n",// // "Born Host:",// // RemotingHelper.parseSocketAddressAddr(msg.getBornHost())// // ); map.put("Born Host:", RemotingHelper.parseSocketAddressAddr(msg.getBornHost())); // System.out.printf("%-20s %s\n",// // "Store Host:",// // RemotingHelper.parseSocketAddressAddr(msg.getStoreHost())// // ); map.put("Store Host:", RemotingHelper.parseSocketAddressAddr(msg.getStoreHost())); // System.out.printf("%-20s %d\n",// // "System Flag:",// // msg.getSysFlag()// // ); map.put("System Flag:", String.valueOf(msg.getSysFlag())); // System.out.printf("%-20s %s\n",// // "Properties:",// // msg.getProperties() != null ? msg.getProperties().toString() : // ""// // ); map.put("Properties:", msg.getProperties() != null ? msg.getProperties().toString() : ""); // System.out.printf("%-20s %s\n",// // "Message Body Path:",// // bodyTmpFilePath// // ); map.put("Message Body Path:", bodyTmpFilePath); return Table.Map2VTable(map); } catch (Throwable e) { logger.error(e.getMessage(), e); t = e; } finally { shutdownDefaultMQAdminExt(defaultMQAdminExt); } throw t; }
Example 19
Source File: ConsumerService.java From rocketmq with Apache License 2.0 | 4 votes |
@CmdTrace(cmdClazz = UpdateSubGroupSubCommand.class) public boolean updateSubGroup(String brokerAddr, String clusterName, String groupName, String consumeEnable, String consumeFromMinEnable, String consumeBroadcastEnable, String retryQueueNums, String retryMaxTimes, String brokerId, String whichBrokerWhenConsumeSlowly) throws Throwable { Throwable t = null; DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt(); try { SubscriptionGroupConfig subscriptionGroupConfig = new SubscriptionGroupConfig(); subscriptionGroupConfig.setConsumeBroadcastEnable(false); subscriptionGroupConfig.setConsumeFromMinEnable(false); // groupName subscriptionGroupConfig.setGroupName(groupName); // consumeEnable if (isNotBlank(consumeEnable)) { subscriptionGroupConfig.setConsumeEnable(Boolean.parseBoolean(consumeEnable.trim())); } // consumeFromMinEnable if (isNotBlank(consumeFromMinEnable)) { subscriptionGroupConfig.setConsumeFromMinEnable(Boolean.parseBoolean(consumeFromMinEnable .trim())); } // consumeBroadcastEnable if (isNotBlank(consumeBroadcastEnable)) { subscriptionGroupConfig.setConsumeBroadcastEnable(Boolean.parseBoolean(consumeBroadcastEnable .trim())); } // retryQueueNums if (isNotBlank(retryQueueNums)) { subscriptionGroupConfig.setRetryQueueNums(Integer.parseInt(retryQueueNums.trim())); } // retryMaxTimes if (isNotBlank(retryMaxTimes)) { subscriptionGroupConfig.setRetryMaxTimes(Integer.parseInt(retryMaxTimes.trim())); } // brokerId if (isNotBlank(brokerId)) { subscriptionGroupConfig.setBrokerId(Long.parseLong(brokerId.trim())); } // whichBrokerWhenConsumeSlowly if (isNotBlank(whichBrokerWhenConsumeSlowly)) { subscriptionGroupConfig.setWhichBrokerWhenConsumeSlowly(Long .parseLong(whichBrokerWhenConsumeSlowly.trim())); } if (isNotBlank(brokerAddr)) { defaultMQAdminExt.start(); defaultMQAdminExt.createAndUpdateSubscriptionGroupConfig(brokerAddr, subscriptionGroupConfig); // System.out.printf("create subscription group to %s success.\n", // addr); // System.out.println(subscriptionGroupConfig); return true; } else if (isNotBlank(clusterName)) { defaultMQAdminExt.start(); Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName); for (String addr : masterSet) { defaultMQAdminExt.createAndUpdateSubscriptionGroupConfig(addr, subscriptionGroupConfig); // System.out.printf("create subscription group to %s success.\n", // addr); } // System.out.println(subscriptionGroupConfig); return true; } else { throw new IllegalStateException("brokerAddr or clusterName can not be all blank"); } } catch (Throwable e) { logger.error(e.getMessage(), e); t = e; } finally { shutdownDefaultMQAdminExt(defaultMQAdminExt); } throw t; }
Example 20
Source File: QueryMsgByOffsetSubCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); defaultMQPullConsumer.setInstanceName(Long.toString(System.currentTimeMillis())); try { //解析 sh mqadmin queryMsgByOffset 命令携带的各种参数信息 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.queryById(defaultMQAdminExt, pullResult.getMsgFoundList().get(0) .getMsgId()); break; case NO_MATCHED_MSG: case NO_NEW_MSG: case OFFSET_ILLEGAL: default: break; } } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQPullConsumer.shutdown(); defaultMQAdminExt.shutdown(); } }