Java Code Examples for org.apache.rocketmq.common.admin.OffsetWrapper#getConsumerOffset()
The following examples show how to use
org.apache.rocketmq.common.admin.OffsetWrapper#getConsumerOffset() .
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: DefaultMQAdminExtImpl.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, OffsetWrapper offsetWrapper, long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { long resetOffset; if (timestamp == -1) { resetOffset = this.mqClientInstance.getMQClientAPIImpl().getMaxOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timeoutMillis); } else { resetOffset = this.mqClientInstance.getMQClientAPIImpl().searchOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timestamp, timeoutMillis); } RollbackStats rollbackStats = new RollbackStats(); rollbackStats.setBrokerName(queue.getBrokerName()); rollbackStats.setQueueId(queue.getQueueId()); rollbackStats.setBrokerOffset(offsetWrapper.getBrokerOffset()); rollbackStats.setConsumerOffset(offsetWrapper.getConsumerOffset()); rollbackStats.setTimestampOffset(resetOffset); rollbackStats.setRollbackOffset(offsetWrapper.getConsumerOffset()); if (force || resetOffset <= offsetWrapper.getConsumerOffset()) { rollbackStats.setRollbackOffset(resetOffset); UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader(); requestHeader.setConsumerGroup(consumeGroup); requestHeader.setTopic(queue.getTopic()); requestHeader.setQueueId(queue.getQueueId()); requestHeader.setCommitOffset(resetOffset); this.mqClientInstance.getMQClientAPIImpl().updateConsumerOffset(brokerAddr, requestHeader, timeoutMillis); } return rollbackStats; }
Example 2
Source File: DefaultMQAdminExtImpl.java From rocketmq-read with Apache License 2.0 | 5 votes |
private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, OffsetWrapper offsetWrapper, long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { long resetOffset; if (timestamp == -1) { resetOffset = this.mqClientInstance.getMQClientAPIImpl().getMaxOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timeoutMillis); } else { resetOffset = this.mqClientInstance.getMQClientAPIImpl().searchOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timestamp, timeoutMillis); } RollbackStats rollbackStats = new RollbackStats(); rollbackStats.setBrokerName(queue.getBrokerName()); rollbackStats.setQueueId(queue.getQueueId()); rollbackStats.setBrokerOffset(offsetWrapper.getBrokerOffset()); rollbackStats.setConsumerOffset(offsetWrapper.getConsumerOffset()); rollbackStats.setTimestampOffset(resetOffset); rollbackStats.setRollbackOffset(offsetWrapper.getConsumerOffset()); if (force || resetOffset <= offsetWrapper.getConsumerOffset()) { rollbackStats.setRollbackOffset(resetOffset); UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader(); requestHeader.setConsumerGroup(consumeGroup); requestHeader.setTopic(queue.getTopic()); requestHeader.setQueueId(queue.getQueueId()); requestHeader.setCommitOffset(resetOffset); this.mqClientInstance.getMQClientAPIImpl().updateConsumerOffset(brokerAddr, requestHeader, timeoutMillis); } return rollbackStats; }
Example 3
Source File: DefaultMQAdminExtImpl.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, OffsetWrapper offsetWrapper, long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { long resetOffset; if (timestamp == -1) { resetOffset = this.mqClientInstance.getMQClientAPIImpl().getMaxOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timeoutMillis); } else { resetOffset = this.mqClientInstance.getMQClientAPIImpl().searchOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timestamp, timeoutMillis); } RollbackStats rollbackStats = new RollbackStats(); rollbackStats.setBrokerName(queue.getBrokerName()); rollbackStats.setQueueId(queue.getQueueId()); rollbackStats.setBrokerOffset(offsetWrapper.getBrokerOffset()); rollbackStats.setConsumerOffset(offsetWrapper.getConsumerOffset()); rollbackStats.setTimestampOffset(resetOffset); rollbackStats.setRollbackOffset(offsetWrapper.getConsumerOffset()); if (force || resetOffset <= offsetWrapper.getConsumerOffset()) { rollbackStats.setRollbackOffset(resetOffset); UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader(); requestHeader.setConsumerGroup(consumeGroup); requestHeader.setTopic(queue.getTopic()); requestHeader.setQueueId(queue.getQueueId()); requestHeader.setCommitOffset(resetOffset); this.mqClientInstance.getMQClientAPIImpl().updateConsumerOffset(brokerAddr, requestHeader, timeoutMillis); } return rollbackStats; }
Example 4
Source File: DefaultMQAdminExtImpl.java From rocketmq with Apache License 2.0 | 5 votes |
private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, OffsetWrapper offsetWrapper, long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { long resetOffset; if (timestamp == -1) { resetOffset = this.mqClientInstance.getMQClientAPIImpl().getMaxOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timeoutMillis); } else { resetOffset = this.mqClientInstance.getMQClientAPIImpl().searchOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timestamp, timeoutMillis); } RollbackStats rollbackStats = new RollbackStats(); rollbackStats.setBrokerName(queue.getBrokerName()); rollbackStats.setQueueId(queue.getQueueId()); rollbackStats.setBrokerOffset(offsetWrapper.getBrokerOffset()); rollbackStats.setConsumerOffset(offsetWrapper.getConsumerOffset()); rollbackStats.setTimestampOffset(resetOffset); rollbackStats.setRollbackOffset(offsetWrapper.getConsumerOffset()); if (force || resetOffset <= offsetWrapper.getConsumerOffset()) { rollbackStats.setRollbackOffset(resetOffset); UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader(); requestHeader.setConsumerGroup(consumeGroup); requestHeader.setTopic(queue.getTopic()); requestHeader.setQueueId(queue.getQueueId()); requestHeader.setCommitOffset(resetOffset); this.mqClientInstance.getMQClientAPIImpl().updateConsumerOffset(brokerAddr, requestHeader, timeoutMillis); } return rollbackStats; }
Example 5
Source File: DefaultMQAdminExtImpl.java From DDMQ with Apache License 2.0 | 5 votes |
private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, OffsetWrapper offsetWrapper, long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { long resetOffset; if (timestamp == -1) { resetOffset = this.mqClientInstance.getMQClientAPIImpl().getMaxOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timeoutMillis); } else { resetOffset = this.mqClientInstance.getMQClientAPIImpl().searchOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timestamp, timeoutMillis); } RollbackStats rollbackStats = new RollbackStats(); rollbackStats.setBrokerName(queue.getBrokerName()); rollbackStats.setQueueId(queue.getQueueId()); rollbackStats.setBrokerOffset(offsetWrapper.getBrokerOffset()); rollbackStats.setConsumerOffset(offsetWrapper.getConsumerOffset()); rollbackStats.setTimestampOffset(resetOffset); rollbackStats.setRollbackOffset(offsetWrapper.getConsumerOffset()); if (force || resetOffset <= offsetWrapper.getConsumerOffset()) { rollbackStats.setRollbackOffset(resetOffset); UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader(); requestHeader.setConsumerGroup(consumeGroup); requestHeader.setTopic(queue.getTopic()); requestHeader.setQueueId(queue.getQueueId()); requestHeader.setCommitOffset(resetOffset); this.mqClientInstance.getMQClientAPIImpl().updateConsumerOffset(brokerAddr, requestHeader, timeoutMillis); } return rollbackStats; }
Example 6
Source File: DefaultMQAdminExtImpl.java From rocketmq with Apache License 2.0 | 5 votes |
private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, OffsetWrapper offsetWrapper, long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { long resetOffset; if (timestamp == -1) { resetOffset = this.mqClientInstance.getMQClientAPIImpl().getMaxOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timeoutMillis); } else { resetOffset = this.mqClientInstance.getMQClientAPIImpl().searchOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timestamp, timeoutMillis); } RollbackStats rollbackStats = new RollbackStats(); rollbackStats.setBrokerName(queue.getBrokerName()); rollbackStats.setQueueId(queue.getQueueId()); rollbackStats.setBrokerOffset(offsetWrapper.getBrokerOffset()); rollbackStats.setConsumerOffset(offsetWrapper.getConsumerOffset()); rollbackStats.setTimestampOffset(resetOffset); rollbackStats.setRollbackOffset(offsetWrapper.getConsumerOffset()); if (force || resetOffset <= offsetWrapper.getConsumerOffset()) { rollbackStats.setRollbackOffset(resetOffset); UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader(); requestHeader.setConsumerGroup(consumeGroup); requestHeader.setTopic(queue.getTopic()); requestHeader.setQueueId(queue.getQueueId()); requestHeader.setCommitOffset(resetOffset); this.mqClientInstance.getMQClientAPIImpl().updateConsumerOffset(brokerAddr, requestHeader, timeoutMillis); } return rollbackStats; }
Example 7
Source File: DefaultMQAdminExtImpl.java From DDMQ with Apache License 2.0 | 5 votes |
private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, OffsetWrapper offsetWrapper, long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { long resetOffset; if (timestamp == -1) { resetOffset = this.mqClientInstance.getMQClientAPIImpl().getMaxOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timeoutMillis); } else { resetOffset = this.mqClientInstance.getMQClientAPIImpl().searchOffset(brokerAddr, queue.getTopic(), queue.getQueueId(), timestamp, timeoutMillis); } RollbackStats rollbackStats = new RollbackStats(); rollbackStats.setBrokerName(queue.getBrokerName()); rollbackStats.setQueueId(queue.getQueueId()); rollbackStats.setBrokerOffset(offsetWrapper.getBrokerOffset()); rollbackStats.setConsumerOffset(offsetWrapper.getConsumerOffset()); rollbackStats.setTimestampOffset(resetOffset); rollbackStats.setRollbackOffset(offsetWrapper.getConsumerOffset()); if (force || resetOffset <= offsetWrapper.getConsumerOffset()) { rollbackStats.setRollbackOffset(resetOffset); UpdateConsumerOffsetRequestHeader requestHeader = new UpdateConsumerOffsetRequestHeader(); requestHeader.setConsumerGroup(consumeGroup); requestHeader.setTopic(queue.getTopic()); requestHeader.setQueueId(queue.getQueueId()); requestHeader.setCommitOffset(resetOffset); this.mqClientInstance.getMQClientAPIImpl().updateConsumerOffset(brokerAddr, requestHeader, timeoutMillis); } return rollbackStats; }
Example 8
Source File: BrokerConsumeStatsSubCommad.java From rocketmq with Apache License 2.0 | 4 votes |
@Override public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException { try { defaultMQAdminExt = createMQAdminExt(rpcHook); String brokerAddr = commandLine.getOptionValue('b').trim(); boolean isOrder = false; long timeoutMillis = 50000; long diffLevel = 0; if (commandLine.hasOption('o')) { isOrder = Boolean.parseBoolean(commandLine.getOptionValue('o').trim()); } if (commandLine.hasOption('t')) { timeoutMillis = Long.parseLong(commandLine.getOptionValue('t').trim()); } if (commandLine.hasOption('l')) { diffLevel = Long.parseLong(commandLine.getOptionValue('l').trim()); } ConsumeStatsList consumeStatsList = defaultMQAdminExt.fetchConsumeStatsInBroker(brokerAddr, isOrder, timeoutMillis); System.out.printf("%-32s %-32s %-32s %-4s %-20s %-20s %-20s %s%n", "#Topic", "#Group", "#Broker Name", "#QID", "#Broker Offset", "#Consumer Offset", "#Diff", "#LastTime"); for (Map<String, List<ConsumeStats>> map : consumeStatsList.getConsumeStatsList()) { for (Map.Entry<String, List<ConsumeStats>> entry : map.entrySet()) { String group = entry.getKey(); List<ConsumeStats> consumeStatsArray = entry.getValue(); for (ConsumeStats consumeStats : consumeStatsArray) { List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(consumeStats.getOffsetTable().keySet()); Collections.sort(mqList); for (MessageQueue mq : mqList) { OffsetWrapper offsetWrapper = consumeStats.getOffsetTable().get(mq); long diff = offsetWrapper.getBrokerOffset() - offsetWrapper.getConsumerOffset(); if (diff < diffLevel) { continue; } String lastTime = "-"; try { lastTime = UtilAll.formatDate(new Date(offsetWrapper.getLastTimestamp()), UtilAll.YYYY_MM_DD_HH_MM_SS); } catch (Exception ignored) { } if (offsetWrapper.getLastTimestamp() > 0) System.out.printf("%-32s %-32s %-32s %-4d %-20d %-20d %-20d %s%n", UtilAll.frontStringAtLeast(mq.getTopic(), 32), group, UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), offsetWrapper.getBrokerOffset(), offsetWrapper.getConsumerOffset(), diff, lastTime ); } } } } System.out.printf("%nDiff Total: %d%n", consumeStatsList.getTotalDiff()); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 9
Source File: MonitorService.java From rocketmq_trans_message 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 10
Source File: BrokerConsumeStatsSubCommad.java From rocketmq_trans_message 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 brokerAddr = commandLine.getOptionValue('b').trim(); boolean isOrder = false; long timeoutMillis = 50000; long diffLevel = 0; if (commandLine.hasOption('o')) { isOrder = Boolean.parseBoolean(commandLine.getOptionValue('o').trim()); } if (commandLine.hasOption('t')) { timeoutMillis = Long.parseLong(commandLine.getOptionValue('t').trim()); } if (commandLine.hasOption('l')) { diffLevel = Long.parseLong(commandLine.getOptionValue('l').trim()); } ConsumeStatsList consumeStatsList = defaultMQAdminExt.fetchConsumeStatsInBroker(brokerAddr, isOrder, timeoutMillis); System.out.printf("%-32s %-32s %-32s %-4s %-20s %-20s %-20s %s%n", "#Topic", "#Group", "#Broker Name", "#QID", "#Broker Offset", "#Consumer Offset", "#Diff", "#LastTime"); for (Map<String, List<ConsumeStats>> map : consumeStatsList.getConsumeStatsList()) { for (Map.Entry<String, List<ConsumeStats>> entry : map.entrySet()) { String group = entry.getKey(); List<ConsumeStats> consumeStatsArray = entry.getValue(); for (ConsumeStats consumeStats : consumeStatsArray) { List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(consumeStats.getOffsetTable().keySet()); Collections.sort(mqList); for (MessageQueue mq : mqList) { OffsetWrapper offsetWrapper = consumeStats.getOffsetTable().get(mq); long diff = offsetWrapper.getBrokerOffset() - offsetWrapper.getConsumerOffset(); if (diff < diffLevel) { continue; } String lastTime = "-"; try { lastTime = UtilAll.formatDate(new Date(offsetWrapper.getLastTimestamp()), UtilAll.YYYY_MM_DD_HH_MM_SS); } catch (Exception ignored) { } if (offsetWrapper.getLastTimestamp() > 0) System.out.printf("%-32s %-32s %-32s %-4d %-20d %-20d %-20d %s%n", UtilAll.frontStringAtLeast(mq.getTopic(), 32), group, UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), offsetWrapper.getBrokerOffset(), offsetWrapper.getConsumerOffset(), diff, lastTime ); } } } } System.out.printf("%nDiff Total: %d%n", consumeStatsList.getTotalDiff()); } catch (Exception e) { e.printStackTrace(); } finally { defaultMQAdminExt.shutdown(); } }
Example 11
Source File: MonitorService.java From rocketmq-all-4.1.0-incubating 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 12
Source File: BrokerConsumeStatsSubCommad.java From rocketmq-all-4.1.0-incubating 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 brokerAddr = commandLine.getOptionValue('b').trim(); boolean isOrder = false; long timeoutMillis = 50000; long diffLevel = 0; if (commandLine.hasOption('o')) { isOrder = Boolean.parseBoolean(commandLine.getOptionValue('o').trim()); } if (commandLine.hasOption('t')) { timeoutMillis = Long.parseLong(commandLine.getOptionValue('t').trim()); } if (commandLine.hasOption('l')) { diffLevel = Long.parseLong(commandLine.getOptionValue('l').trim()); } ConsumeStatsList consumeStatsList = defaultMQAdminExt.fetchConsumeStatsInBroker(brokerAddr, isOrder, timeoutMillis); System.out.printf("%-32s %-32s %-32s %-4s %-20s %-20s %-20s %s%n", "#Topic", "#Group", "#Broker Name", "#QID", "#Broker Offset", "#Consumer Offset", "#Diff", "#LastTime"); for (Map<String, List<ConsumeStats>> map : consumeStatsList.getConsumeStatsList()) { for (Map.Entry<String, List<ConsumeStats>> entry : map.entrySet()) { String group = entry.getKey(); List<ConsumeStats> consumeStatsArray = entry.getValue(); for (ConsumeStats consumeStats : consumeStatsArray) { List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(consumeStats.getOffsetTable().keySet()); Collections.sort(mqList); for (MessageQueue mq : mqList) { OffsetWrapper offsetWrapper = consumeStats.getOffsetTable().get(mq); long diff = offsetWrapper.getBrokerOffset() - offsetWrapper.getConsumerOffset(); if (diff < diffLevel) { continue; } String lastTime = "-"; try { lastTime = UtilAll.formatDate(new Date(offsetWrapper.getLastTimestamp()), UtilAll.YYYY_MM_DD_HH_MM_SS); } catch (Exception ignored) { } if (offsetWrapper.getLastTimestamp() > 0) System.out.printf("%-32s %-32s %-32s %-4d %-20d %-20d %-20d %s%n", UtilAll.frontStringAtLeast(mq.getTopic(), 32), group, UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), offsetWrapper.getBrokerOffset(), offsetWrapper.getConsumerOffset(), diff, lastTime ); } } } } System.out.printf("%nDiff Total: %d%n", consumeStatsList.getTotalDiff()); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 13
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 14
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 15
Source File: MonitorService.java From rocketmq-read 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 16
Source File: BrokerConsumeStatsSubCommad.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 { defaultMQAdminExt.start(); String brokerAddr = commandLine.getOptionValue('b').trim(); boolean isOrder = false; long timeoutMillis = 50000; long diffLevel = 0; if (commandLine.hasOption('o')) { isOrder = Boolean.parseBoolean(commandLine.getOptionValue('o').trim()); } if (commandLine.hasOption('t')) { timeoutMillis = Long.parseLong(commandLine.getOptionValue('t').trim()); } if (commandLine.hasOption('l')) { diffLevel = Long.parseLong(commandLine.getOptionValue('l').trim()); } ConsumeStatsList consumeStatsList = defaultMQAdminExt.fetchConsumeStatsInBroker(brokerAddr, isOrder, timeoutMillis); System.out.printf("%-32s %-32s %-32s %-4s %-20s %-20s %-20s %s%n", "#Topic", "#Group", "#Broker Name", "#QID", "#Broker Offset", "#Consumer Offset", "#Diff", "#LastTime"); for (Map<String, List<ConsumeStats>> map : consumeStatsList.getConsumeStatsList()) { for (Map.Entry<String, List<ConsumeStats>> entry : map.entrySet()) { String group = entry.getKey(); List<ConsumeStats> consumeStatsArray = entry.getValue(); for (ConsumeStats consumeStats : consumeStatsArray) { List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(consumeStats.getOffsetTable().keySet()); Collections.sort(mqList); for (MessageQueue mq : mqList) { OffsetWrapper offsetWrapper = consumeStats.getOffsetTable().get(mq); long diff = offsetWrapper.getBrokerOffset() - offsetWrapper.getConsumerOffset(); if (diff < diffLevel) { continue; } String lastTime = "-"; try { lastTime = UtilAll.formatDate(new Date(offsetWrapper.getLastTimestamp()), UtilAll.YYYY_MM_DD_HH_MM_SS); } catch (Exception ignored) { } if (offsetWrapper.getLastTimestamp() > 0) System.out.printf("%-32s %-32s %-32s %-4d %-20d %-20d %-20d %s%n", UtilAll.frontStringAtLeast(mq.getTopic(), 32), group, UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), offsetWrapper.getBrokerOffset(), offsetWrapper.getConsumerOffset(), diff, lastTime ); } } } } System.out.printf("%nDiff Total: %d%n", consumeStatsList.getTotalDiff()); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 17
Source File: MonitorService.java From rocketmq-4.3.0 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 18
Source File: BrokerConsumeStatsSubCommad.java From rocketmq-4.3.0 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 brokerAddr = commandLine.getOptionValue('b').trim(); boolean isOrder = false; long timeoutMillis = 50000; long diffLevel = 0; if (commandLine.hasOption('o')) { isOrder = Boolean.parseBoolean(commandLine.getOptionValue('o').trim()); } if (commandLine.hasOption('t')) { timeoutMillis = Long.parseLong(commandLine.getOptionValue('t').trim()); } if (commandLine.hasOption('l')) { diffLevel = Long.parseLong(commandLine.getOptionValue('l').trim()); } ConsumeStatsList consumeStatsList = defaultMQAdminExt.fetchConsumeStatsInBroker(brokerAddr, isOrder, timeoutMillis); System.out.printf("%-32s %-32s %-32s %-4s %-20s %-20s %-20s %s%n", "#Topic", "#Group", "#Broker Name", "#QID", "#Broker Offset", "#Consumer Offset", "#Diff", "#LastTime"); for (Map<String, List<ConsumeStats>> map : consumeStatsList.getConsumeStatsList()) { for (Map.Entry<String, List<ConsumeStats>> entry : map.entrySet()) { String group = entry.getKey(); List<ConsumeStats> consumeStatsArray = entry.getValue(); for (ConsumeStats consumeStats : consumeStatsArray) { List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(consumeStats.getOffsetTable().keySet()); Collections.sort(mqList); for (MessageQueue mq : mqList) { OffsetWrapper offsetWrapper = consumeStats.getOffsetTable().get(mq); long diff = offsetWrapper.getBrokerOffset() - offsetWrapper.getConsumerOffset(); if (diff < diffLevel) { continue; } String lastTime = "-"; try { lastTime = UtilAll.formatDate(new Date(offsetWrapper.getLastTimestamp()), UtilAll.YYYY_MM_DD_HH_MM_SS); } catch (Exception ignored) { } if (offsetWrapper.getLastTimestamp() > 0) System.out.printf("%-32s %-32s %-32s %-4d %-20d %-20d %-20d %s%n", UtilAll.frontStringAtLeast(mq.getTopic(), 32), group, UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), offsetWrapper.getBrokerOffset(), offsetWrapper.getConsumerOffset(), diff, lastTime ); } } } } System.out.printf("%nDiff Total: %d%n", consumeStatsList.getTotalDiff()); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }
Example 19
Source File: MonitorService.java From DDMQ 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 20
Source File: BrokerConsumeStatsSubCommad.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 brokerAddr = commandLine.getOptionValue('b').trim(); boolean isOrder = false; long timeoutMillis = 50000; long diffLevel = 0; if (commandLine.hasOption('o')) { isOrder = Boolean.parseBoolean(commandLine.getOptionValue('o').trim()); } if (commandLine.hasOption('t')) { timeoutMillis = Long.parseLong(commandLine.getOptionValue('t').trim()); } if (commandLine.hasOption('l')) { diffLevel = Long.parseLong(commandLine.getOptionValue('l').trim()); } ConsumeStatsList consumeStatsList = defaultMQAdminExt.fetchConsumeStatsInBroker(brokerAddr, isOrder, timeoutMillis); System.out.printf("%-32s %-32s %-32s %-4s %-20s %-20s %-20s %s%n", "#Topic", "#Group", "#Broker Name", "#QID", "#Broker Offset", "#Consumer Offset", "#Diff", "#LastTime"); for (Map<String, List<ConsumeStats>> map : consumeStatsList.getConsumeStatsList()) { for (Map.Entry<String, List<ConsumeStats>> entry : map.entrySet()) { String group = entry.getKey(); List<ConsumeStats> consumeStatsArray = entry.getValue(); for (ConsumeStats consumeStats : consumeStatsArray) { List<MessageQueue> mqList = new LinkedList<MessageQueue>(); mqList.addAll(consumeStats.getOffsetTable().keySet()); Collections.sort(mqList); for (MessageQueue mq : mqList) { OffsetWrapper offsetWrapper = consumeStats.getOffsetTable().get(mq); long diff = offsetWrapper.getBrokerOffset() - offsetWrapper.getConsumerOffset(); if (diff < diffLevel) { continue; } String lastTime = "-"; try { lastTime = UtilAll.formatDate(new Date(offsetWrapper.getLastTimestamp()), UtilAll.YYYY_MM_DD_HH_MM_SS); } catch (Exception ignored) { } if (offsetWrapper.getLastTimestamp() > 0) System.out.printf("%-32s %-32s %-32s %-4d %-20d %-20d %-20d %s%n", UtilAll.frontStringAtLeast(mq.getTopic(), 32), group, UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), offsetWrapper.getBrokerOffset(), offsetWrapper.getConsumerOffset(), diff, lastTime ); } } } } System.out.printf("%nDiff Total: %d%n", consumeStatsList.getTotalDiff()); } catch (Exception e) { throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e); } finally { defaultMQAdminExt.shutdown(); } }