com.alibaba.rocketmq.common.admin.TopicStatsTable Java Examples
The following examples show how to use
com.alibaba.rocketmq.common.admin.TopicStatsTable.
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: MQClientAPIImpl.java From rocketmq with Apache License 2.0 | 6 votes |
public TopicStatsTable getTopicStatsInfo(final String addr, final String topic, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { GetTopicStatsInfoRequestHeader requestHeader = new GetTopicStatsInfoRequestHeader(); requestHeader.setTopic(topic); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_TOPIC_STATS_INFO, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { TopicStatsTable topicStatsTable = TopicStatsTable.decode(response.getBody(), TopicStatsTable.class); return topicStatsTable; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #2
Source File: MQClientAPIImpl.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 6 votes |
public TopicStatsTable getTopicStatsInfo(final String addr, final String topic, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { GetTopicStatsInfoRequestHeader requestHeader = new GetTopicStatsInfoRequestHeader(); requestHeader.setTopic(topic); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_TOPIC_STATS_INFO, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { TopicStatsTable topicStatsTable = TopicStatsTable.decode(response.getBody(), TopicStatsTable.class); return topicStatsTable; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #3
Source File: MQClientAPIImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
/** * 获取topic状态相关信息 * * @param addr * @param topic * @param timeoutMillis * @return * @throws InterruptedException * @throws RemotingTimeoutException * @throws RemotingSendRequestException * @throws RemotingConnectException * @throws MQBrokerException */ public TopicStatsTable getTopicStatsInfo(final String addr, final String topic, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { String topicWithProjectGroup = topic; if (!UtilAll.isBlank(projectGroupPrefix)) { topicWithProjectGroup = VirtualEnvUtil.buildWithProjectGroup(topic, projectGroupPrefix); } GetTopicStatsInfoRequestHeader requestHeader = new GetTopicStatsInfoRequestHeader(); requestHeader.setTopic(topicWithProjectGroup); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_TOPIC_STATS_INFO, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { TopicStatsTable topicStatsTable = TopicStatsTable.decode(response.getBody(), TopicStatsTable.class); if (!UtilAll.isBlank(projectGroupPrefix)) { HashMap<MessageQueue, TopicOffset> newTopicOffsetMap = new HashMap<MessageQueue, TopicOffset>(); for (Map.Entry<MessageQueue, TopicOffset> messageQueue : topicStatsTable.getOffsetTable() .entrySet()) { MessageQueue key = messageQueue.getKey(); key.setTopic(VirtualEnvUtil.clearProjectGroup(key.getTopic(), projectGroupPrefix)); newTopicOffsetMap.put(key, messageQueue.getValue()); } topicStatsTable.setOffsetTable(newTopicOffsetMap); } return topicStatsTable; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #4
Source File: TopicServiceImpl.java From rocket-console with Apache License 2.0 | 5 votes |
@Override public TopicStatsTable stats(String topic) { try { return mqAdminExt.examineTopicStats(topic); } catch (Exception e) { throw Throwables.propagate(e); } }
Example #5
Source File: TopicService.java From rocketmq with Apache License 2.0 | 4 votes |
@CmdTrace(cmdClazz = TopicStatusSubCommand.class) public Table stats(String topicName) throws Throwable { Throwable t = null; DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt(); try { defaultMQAdminExt.start(); TopicStatsTable topicStatsTable = defaultMQAdminExt.examineTopicStats(topicName); List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(topicStatsTable.getOffsetTable().keySet()); Collections.sort(mqList); // System.out.printf("%-32s %-4s %-20s %-20s %s\n",// // "#Broker Name",// // "#QID",// // "#Min Offset",// // "#Max Offset",// // "#Last Updated" // // ); String[] thead = new String[] { "#Broker Name", "#QID", "#Min Offset", "#Max Offset", "#Last Updated" }; Table table = new Table(thead, mqList.size()); for (MessageQueue mq : mqList) { TopicOffset topicOffset = topicStatsTable.getOffsetTable().get(mq); String humanTimestamp = ""; if (topicOffset.getLastUpdateTimestamp() > 0) { humanTimestamp = UtilAll.timeMillisToHumanString2(topicOffset.getLastUpdateTimestamp()); } Object[] tr = table.createTR(); tr[0] = UtilAll.frontStringAtLeast(mq.getBrokerName(), 32); tr[1] = str(mq.getQueueId()); tr[2] = str(topicOffset.getMinOffset()); tr[3] = str(topicOffset.getMaxOffset()); tr[4] = humanTimestamp; table.insertTR(tr); // System.out.printf("%-32s %-4d %-20d %-20d %s\n",// // UtilAll.frontStringAtLeast(mq.getBrokerName(), 32),// // mq.getQueueId(),// // topicOffset.getMinOffset(),// // topicOffset.getMaxOffset(),// // humanTimestamp // // ); } return table; } catch (Throwable e) { logger.error(e.getMessage(), e); t = e; } finally { shutdownDefaultMQAdminExt(defaultMQAdminExt); } throw t; }
Example #6
Source File: AdminBrokerProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetTopicStatsInfoRequestHeader requestHeader = (GetTopicStatsInfoRequestHeader) request .decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); final String topic = requestHeader.getTopic(); TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("topic[" + topic + "] not exist"); return response; } TopicStatsTable topicStatsTable = new TopicStatsTable(); for (int i = 0; i < topicConfig.getWriteQueueNums(); i++) { MessageQueue mq = new MessageQueue(); mq.setTopic(topic); mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); mq.setQueueId(i); TopicOffset topicOffset = new TopicOffset(); long min = this.brokerController.getMessageStore().getMinOffsetInQuque(topic, i); if (min < 0) min = 0; long max = this.brokerController.getMessageStore().getMaxOffsetInQuque(topic, i); if (max < 0) max = 0; long timestamp = 0; if (max > 0) { timestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, (max - 1)); } topicOffset.setMinOffset(min); topicOffset.setMaxOffset(max); topicOffset.setLastUpdateTimestamp(timestamp); topicStatsTable.getOffsetTable().put(mq, topicOffset); } byte[] body = topicStatsTable.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #7
Source File: TopicStatusSubCommand.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 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(); TopicStatsTable topicStatsTable = defaultMQAdminExt.examineTopicStats(topic); List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(topicStatsTable.getOffsetTable().keySet()); Collections.sort(mqList); System.out.printf("%-32s %-4s %-20s %-20s %s\n", // "#Broker Name", // "#QID", // "#Min Offset", // "#Max Offset", // "#Last Updated" // ); for (MessageQueue mq : mqList) { TopicOffset topicOffset = topicStatsTable.getOffsetTable().get(mq); String humanTimestamp = ""; if (topicOffset.getLastUpdateTimestamp() > 0) { humanTimestamp = UtilAll.timeMillisToHumanString2(topicOffset.getLastUpdateTimestamp()); } System.out.printf("%-32s %-4d %-20d %-20d %s\n", // UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), // mq.getQueueId(), // topicOffset.getMinOffset(), // topicOffset.getMaxOffset(), // humanTimestamp // ); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example #8
Source File: DefaultMQAdminExt.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
@Override public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.examineTopicStats(topic); }
Example #9
Source File: AdminBrokerProcessor.java From rocketmq with Apache License 2.0 | 4 votes |
private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetTopicStatsInfoRequestHeader requestHeader = (GetTopicStatsInfoRequestHeader) request.decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); final String topic = requestHeader.getTopic(); TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("topic[" + topic + "] not exist"); return response; } TopicStatsTable topicStatsTable = new TopicStatsTable(); for (int i = 0; i < topicConfig.getWriteQueueNums(); i++) { MessageQueue mq = new MessageQueue(); mq.setTopic(topic); mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); mq.setQueueId(i); TopicOffset topicOffset = new TopicOffset(); long min = this.brokerController.getMessageStore().getMinOffsetInQuque(topic, i); if (min < 0) min = 0; long max = this.brokerController.getMessageStore().getMaxOffsetInQuque(topic, i); if (max < 0) max = 0; long timestamp = 0; if (max > 0) { timestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, (max - 1)); } topicOffset.setMinOffset(min); topicOffset.setMaxOffset(max); topicOffset.setLastUpdateTimestamp(timestamp); topicStatsTable.getOffsetTable().put(mq, topicOffset); } byte[] body = topicStatsTable.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #10
Source File: TopicStatusSubCommand.java From rocketmq with Apache License 2.0 | 4 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(); TopicStatsTable topicStatsTable = defaultMQAdminExt.examineTopicStats(topic); List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(topicStatsTable.getOffsetTable().keySet()); Collections.sort(mqList); System.out.printf("%-32s %-4s %-20s %-20s %s%n",// "#Broker Name",// "#QID",// "#Min Offset",// "#Max Offset",// "#Last Updated" // ); for (MessageQueue mq : mqList) { TopicOffset topicOffset = topicStatsTable.getOffsetTable().get(mq); String humanTimestamp = ""; if (topicOffset.getLastUpdateTimestamp() > 0) { humanTimestamp = UtilAll.timeMillisToHumanString2(topicOffset.getLastUpdateTimestamp()); } System.out.printf("%-32s %-4d %-20d %-20d %s%n",// UtilAll.frontStringAtLeast(mq.getBrokerName(), 32),// mq.getQueueId(),// topicOffset.getMinOffset(),// topicOffset.getMaxOffset(),// humanTimestamp // ); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example #11
Source File: MQAdminExt.java From rocketmq with Apache License 2.0 | 4 votes |
TopicStatsTable examineTopicStats(final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException;
Example #12
Source File: DefaultMQAdminExt.java From rocketmq with Apache License 2.0 | 4 votes |
@Override public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.examineTopicStats(topic); }
Example #13
Source File: MQAdminExtImpl.java From rocket-console with Apache License 2.0 | 4 votes |
@Override public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return MQAdminInstance.threadLocalMQAdminExt().examineTopicStats(topic); }
Example #14
Source File: AdminBrokerProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetTopicStatsInfoRequestHeader requestHeader = (GetTopicStatsInfoRequestHeader) request.decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); final String topic = requestHeader.getTopic(); TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { response.setCode(ResponseCode.TOPIC_NOT_EXIST); response.setRemark("topic[" + topic + "] not exist"); return response; } TopicStatsTable topicStatsTable = new TopicStatsTable(); for (int i = 0; i < topicConfig.getWriteQueueNums(); i++) { MessageQueue mq = new MessageQueue(); mq.setTopic(topic); mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); mq.setQueueId(i); TopicOffset topicOffset = new TopicOffset(); long min = this.brokerController.getMessageStore().getMinOffsetInQuque(topic, i); if (min < 0) min = 0; long max = this.brokerController.getMessageStore().getMaxOffsetInQuque(topic, i); if (max < 0) max = 0; long timestamp = 0; if (max > 0) { timestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, (max - 1)); } topicOffset.setMinOffset(min); topicOffset.setMaxOffset(max); topicOffset.setLastUpdateTimestamp(timestamp); topicStatsTable.getOffsetTable().put(mq, topicOffset); } byte[] body = topicStatsTable.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #15
Source File: TopicStatusSubCommand.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 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(); TopicStatsTable topicStatsTable = defaultMQAdminExt.examineTopicStats(topic); List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(topicStatsTable.getOffsetTable().keySet()); Collections.sort(mqList); System.out.printf("%-32s %-4s %-20s %-20s %s\n",// "#Broker Name",// "#QID",// "#Min Offset",// "#Max Offset",// "#Last Updated" // ); for (MessageQueue mq : mqList) { TopicOffset topicOffset = topicStatsTable.getOffsetTable().get(mq); String humanTimestamp = ""; if (topicOffset.getLastUpdateTimestamp() > 0) { humanTimestamp = UtilAll.timeMillisToHumanString2(topicOffset.getLastUpdateTimestamp()); } System.out.printf("%-32s %-4d %-20d %-20d %s\n",// UtilAll.frontStringAtLeast(mq.getBrokerName(), 32),// mq.getQueueId(),// topicOffset.getMinOffset(),// topicOffset.getMaxOffset(),// humanTimestamp // ); } } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example #16
Source File: MQAdminExt.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
TopicStatsTable examineTopicStats(final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException;
Example #17
Source File: DefaultMQAdminExt.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
@Override public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.examineTopicStats(topic); }
Example #18
Source File: MQAdminExt.java From RocketMQ-Master-analyze with Apache License 2.0 | 2 votes |
/** * 查询Topic Offset信息 * * @param topic * @return */ public TopicStatsTable examineTopicStats(final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException;
Example #19
Source File: TopicService.java From rocket-console with Apache License 2.0 | votes |
TopicStatsTable stats(String topic);