com.alibaba.rocketmq.common.admin.OffsetWrapper Java Examples
The following examples show how to use
com.alibaba.rocketmq.common.admin.OffsetWrapper.
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: MonitorService.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
private void computeUndoneMsgs(final UndoneMsgs undoneMsgs, final ConsumeStats consumeStats) { long total = 0; long singleMax = 0; long delayMax = 0; Iterator<Entry<MessageQueue, OffsetWrapper>> it = consumeStats.getOffsetTable().entrySet().iterator(); while (it.hasNext()) { Entry<MessageQueue, OffsetWrapper> next = it.next(); MessageQueue mq = next.getKey(); OffsetWrapper ow = next.getValue(); long diff = ow.getBrokerOffset() - ow.getConsumerOffset(); if (diff > singleMax) { singleMax = diff; } if (diff > 0) { total += diff; } // Delay if (ow.getLastTimestamp() > 0) { try { long maxOffset = this.defaultMQPullConsumer.maxOffset(mq); if (maxOffset > 0) { PullResult pull = this.defaultMQPullConsumer.pull(mq, "*", maxOffset - 1, 1); switch (pull.getPullStatus()) { case FOUND: long delay = pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp(); if (delay > delayMax) { delayMax = delay; } break; case NO_MATCHED_MSG: case NO_NEW_MSG: case OFFSET_ILLEGAL: break; default: break; } } } catch (Exception e) { } } } undoneMsgs.setUndoneMsgsTotal(total); undoneMsgs.setUndoneMsgsSingleMQ(singleMax); undoneMsgs.setUndoneMsgsDelayTimeMills(delayMax); }
Example #2
Source File: AdminBrokerProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumeStatsRequestHeader requestHeader = (GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); ConsumeStats consumeStats = new ConsumeStats(); Set<String> topics = new HashSet<String>(); if (UtilAll.isBlank(requestHeader.getTopic())) { topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getConsumerGroup()); } else { topics.add(requestHeader.getTopic()); } for (String topic : topics) { TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { log.warn("consumeStats, topic config not exist, {}", topic); continue; } { SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic); if (null == findSubscriptionData // && this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic); continue; } } for (int i = 0; i < topicConfig.getReadQueueNums(); i++) { MessageQueue mq = new MessageQueue(); mq.setTopic(topic); mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); mq.setQueueId(i); OffsetWrapper offsetWrapper = new OffsetWrapper(); long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQuque(topic, i); if (brokerOffset < 0) brokerOffset = 0; long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(// requestHeader.getConsumerGroup(),// topic,// i); if (consumerOffset < 0) consumerOffset = 0; offsetWrapper.setBrokerOffset(brokerOffset); offsetWrapper.setConsumerOffset(consumerOffset); long timeOffset = consumerOffset - 1; if (timeOffset >= 0) { long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset); if (lastTimestamp > 0) { offsetWrapper.setLastTimestamp(lastTimestamp); } } consumeStats.getOffsetTable().put(mq, offsetWrapper); } double consumeTps = this.brokerController.getBrokerStatsManager().tpsGroupGetNums(requestHeader.getConsumerGroup(), topic); consumeTps += consumeStats.getConsumeTps(); consumeStats.setConsumeTps(consumeTps); } byte[] body = consumeStats.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #3
Source File: QueueStatInfo.java From rocket-console with Apache License 2.0 | 4 votes |
public static QueueStatInfo fromOffsetTableEntry(MessageQueue key, OffsetWrapper value){ QueueStatInfo queueStatInfo = new QueueStatInfo(); BeanUtils.copyProperties(key,queueStatInfo); BeanUtils.copyProperties(value,queueStatInfo); return queueStatInfo; }
Example #4
Source File: MonitorService.java From rocketmq with Apache License 2.0 | 4 votes |
private void computeUndoneMsgs(final UndoneMsgs undoneMsgs, final ConsumeStats consumeStats) { long total = 0; long singleMax = 0; long delayMax = 0; Iterator<Entry<MessageQueue, OffsetWrapper>> it = consumeStats.getOffsetTable().entrySet().iterator(); while (it.hasNext()) { Entry<MessageQueue, OffsetWrapper> next = it.next(); MessageQueue mq = next.getKey(); OffsetWrapper ow = next.getValue(); long diff = ow.getBrokerOffset() - ow.getConsumerOffset(); if (diff > singleMax) { singleMax = diff; } if (diff > 0) { total += diff; } // Delay if (ow.getLastTimestamp() > 0) { try { long maxOffset = this.defaultMQPullConsumer.maxOffset(mq); if (maxOffset > 0) { PullResult pull = this.defaultMQPullConsumer.pull(mq, "*", maxOffset - 1, 1); switch (pull.getPullStatus()) { case FOUND: long delay = pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp(); if (delay > delayMax) { delayMax = delay; } break; case NO_MATCHED_MSG: case NO_NEW_MSG: case OFFSET_ILLEGAL: break; default: break; } } } catch (Exception e) { } } } undoneMsgs.setUndoneMsgsTotal(total); undoneMsgs.setUndoneMsgsSingleMQ(singleMax); undoneMsgs.setUndoneMsgsDelayTimeMills(delayMax); }
Example #5
Source File: AdminBrokerProcessor.java From rocketmq with Apache License 2.0 | 4 votes |
private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumeStatsRequestHeader requestHeader = (GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); ConsumeStats consumeStats = new ConsumeStats(); Set<String> topics = new HashSet<String>(); if (UtilAll.isBlank(requestHeader.getTopic())) { topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getConsumerGroup()); } else { topics.add(requestHeader.getTopic()); } for (String topic : topics) { TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { log.warn("consumeStats, topic config not exist, {}", topic); continue; } /** */ { SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic); if (null == findSubscriptionData // && this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic); continue; } } for (int i = 0; i < topicConfig.getReadQueueNums(); i++) { MessageQueue mq = new MessageQueue(); mq.setTopic(topic); mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); mq.setQueueId(i); OffsetWrapper offsetWrapper = new OffsetWrapper(); long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQuque(topic, i); if (brokerOffset < 0) brokerOffset = 0; long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(// requestHeader.getConsumerGroup(), // topic, // i); if (consumerOffset < 0) consumerOffset = 0; offsetWrapper.setBrokerOffset(brokerOffset); offsetWrapper.setConsumerOffset(consumerOffset); long timeOffset = consumerOffset - 1; if (timeOffset >= 0) { long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset); if (lastTimestamp > 0) { offsetWrapper.setLastTimestamp(lastTimestamp); } } consumeStats.getOffsetTable().put(mq, offsetWrapper); } double consumeTps = this.brokerController.getBrokerStatsManager().tpsGroupGetNums(requestHeader.getConsumerGroup(), topic); consumeTps += consumeStats.getConsumeTps(); consumeStats.setConsumeTps(consumeTps); } byte[] body = consumeStats.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example #6
Source File: MQClientAPIImpl.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
/** * 从Broker获取消费状态(进度) * * @param addr * @param consumerGroup * @param topic * @param timeoutMillis * @return * @throws InterruptedException * @throws RemotingTimeoutException * @throws RemotingSendRequestException * @throws RemotingConnectException * @throws MQBrokerException */ public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { String consumerGroupWithProjectGroup = consumerGroup; if (!UtilAll.isBlank(projectGroupPrefix)) { consumerGroupWithProjectGroup = VirtualEnvUtil.buildWithProjectGroup(consumerGroup, projectGroupPrefix); } GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader(); requestHeader.setConsumerGroup(consumerGroupWithProjectGroup); requestHeader.setTopic(topic); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUME_STATS, requestHeader); RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); switch (response.getCode()) { case ResponseCode.SUCCESS: { ConsumeStats consumeStats = ConsumeStats.decode(response.getBody(), ConsumeStats.class); if (!UtilAll.isBlank(projectGroupPrefix)) { HashMap<MessageQueue, OffsetWrapper> newTopicOffsetMap = new HashMap<MessageQueue, OffsetWrapper>(); for (Map.Entry<MessageQueue, OffsetWrapper> messageQueue : consumeStats.getOffsetTable() .entrySet()) { MessageQueue key = messageQueue.getKey(); key.setTopic(VirtualEnvUtil.clearProjectGroup(key.getTopic(), projectGroupPrefix)); newTopicOffsetMap.put(key, messageQueue.getValue()); } consumeStats.setOffsetTable(newTopicOffsetMap); } return consumeStats; } default: break; } throw new MQBrokerException(response.getCode(), response.getRemark()); }
Example #7
Source File: MonitorService.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
private void computeUndoneMsgs(final UndoneMsgs undoneMsgs, final ConsumeStats consumeStats) { long total = 0; long singleMax = 0; long delayMax = 0; Iterator<Entry<MessageQueue, OffsetWrapper>> it = consumeStats.getOffsetTable().entrySet().iterator(); while (it.hasNext()) { Entry<MessageQueue, OffsetWrapper> next = it.next(); MessageQueue mq = next.getKey(); OffsetWrapper ow = next.getValue(); long diff = ow.getBrokerOffset() - ow.getConsumerOffset(); if (diff > singleMax) { singleMax = diff; } if (diff > 0) { total += diff; } // Delay if (ow.getLastTimestamp() > 0) { try { long maxOffset = this.defaultMQPullConsumer.maxOffset(mq); if (maxOffset > 0) { PullResult pull = this.defaultMQPullConsumer.pull(mq, "*", maxOffset - 1, 1); switch (pull.getPullStatus()) { case FOUND: long delay = pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp(); if (delay > delayMax) { delayMax = delay; } break; case NO_MATCHED_MSG: case NO_NEW_MSG: case OFFSET_ILLEGAL: break; default: break; } } } catch (Exception e) { } } } undoneMsgs.setUndoneMsgsTotal(total); undoneMsgs.setUndoneMsgsSingleMQ(singleMax); undoneMsgs.setUndoneMsgsDelayTimeMills(delayMax); }
Example #8
Source File: AdminBrokerProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumeStatsRequestHeader requestHeader = (GetConsumeStatsRequestHeader) request .decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); ConsumeStats consumeStats = new ConsumeStats(); Set<String> topics = new HashSet<String>(); if (UtilAll.isBlank(requestHeader.getTopic())) { topics = this.brokerController.getConsumerOffsetManager() .whichTopicByConsumer(requestHeader.getConsumerGroup()); } else { topics.add(requestHeader.getTopic()); } for (String topic : topics) { TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic); if (null == topicConfig) { log.warn("consumeStats, topic config not exist, {}", topic); continue; } /** * Consumer不在线的时候,也允许查询消费进度 */ { SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager() .findSubscriptionData(requestHeader.getConsumerGroup(), topic); // 如果Consumer在线,而且这个topic没有被订阅,那么就跳过 if (null == findSubscriptionData // && this.brokerController.getConsumerManager() .findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic); continue; } } for (int i = 0; i < topicConfig.getWriteQueueNums(); i++) { MessageQueue mq = new MessageQueue(); mq.setTopic(topic); mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName()); mq.setQueueId(i); OffsetWrapper offsetWrapper = new OffsetWrapper(); long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQuque(topic, i); if (brokerOffset < 0) brokerOffset = 0; long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(// requestHeader.getConsumerGroup(), // topic, // i); if (consumerOffset < 0) consumerOffset = 0; offsetWrapper.setBrokerOffset(brokerOffset); offsetWrapper.setConsumerOffset(consumerOffset); // 查询消费者最后一条消息对应的时间戳 long timeOffset = consumerOffset - 1; if (timeOffset >= 0) { long lastTimestamp = this.brokerController.getMessageStore() .getMessageStoreTimeStamp(topic, i, timeOffset); if (lastTimestamp > 0) { offsetWrapper.setLastTimestamp(lastTimestamp); } } consumeStats.getOffsetTable().put(mq, offsetWrapper); } long consumeTps = (long) this.brokerController.getBrokerStatsManager() .tpsGroupGetNums(requestHeader.getConsumerGroup(), topic); consumeTps += consumeStats.getConsumeTps(); consumeStats.setConsumeTps(consumeTps); } byte[] body = consumeStats.encode(); response.setBody(body); response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }