Search in sources :

Example 6 with OffsetWrapper

use of org.apache.rocketmq.common.admin.OffsetWrapper in project rocketmq by apache.

the class DefaultMQAdminExtTest method init.

@BeforeClass
public static void init() throws Exception {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);
    properties.setProperty("maxMessageSize", "5000000");
    properties.setProperty("flushDelayOffsetInterval", "15000");
    properties.setProperty("serverSocketRcvBufSize", "655350");
    when(mQClientAPIImpl.getBrokerConfig(anyString(), anyLong())).thenReturn(properties);
    Set<String> topicSet = new HashSet<>();
    topicSet.add("topic_one");
    topicSet.add("topic_two");
    topicList.setTopicList(topicSet);
    when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList);
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    topicRouteData.setQueueDatas(new ArrayList<QueueData>());
    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
    HashMap<String, String> result = new HashMap<>();
    result.put("id", "1234");
    result.put("brokerName", "default-broker");
    kvTable.setTable(result);
    when(mQClientAPIImpl.getBrokerRuntimeInfo(anyString(), anyLong())).thenReturn(kvTable);
    HashMap<String, BrokerData> brokerAddrTable = new HashMap<>();
    brokerAddrTable.put("default-broker", brokerData);
    brokerAddrTable.put("broker-test", new BrokerData());
    clusterInfo.setBrokerAddrTable(brokerAddrTable);
    clusterInfo.setClusterAddrTable(new HashMap<String, Set<String>>());
    when(mQClientAPIImpl.getBrokerClusterInfo(anyLong())).thenReturn(clusterInfo);
    when(mQClientAPIImpl.cleanExpiredConsumeQueue(anyString(), anyLong())).thenReturn(true);
    Set<String> clusterList = new HashSet<>();
    clusterList.add("default-cluster-one");
    clusterList.add("default-cluster-two");
    when(mQClientAPIImpl.getClusterList(anyString(), anyLong())).thenReturn(clusterList);
    GroupList groupList = new GroupList();
    HashSet<String> groups = new HashSet<>();
    groups.add("consumer-group-one");
    groups.add("consumer-group-two");
    groupList.setGroupList(groups);
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
    when(mQClientAPIImpl.queryTopicConsumeByWho(anyString(), anyString(), anyLong())).thenReturn(groupList);
    SubscriptionGroupWrapper subscriptionGroupWrapper = new SubscriptionGroupWrapper();
    ConcurrentHashMap<String, SubscriptionGroupConfig> subscriptions = new ConcurrentHashMap<>();
    SubscriptionGroupConfig subscriptionGroupConfig = new SubscriptionGroupConfig();
    subscriptionGroupConfig.setConsumeBroadcastEnable(true);
    subscriptionGroupConfig.setBrokerId(1234);
    subscriptionGroupConfig.setGroupName("Consumer-group-one");
    subscriptions.put("Consumer-group-one", subscriptionGroupConfig);
    subscriptionGroupWrapper.setSubscriptionGroupTable(subscriptions);
    when(mQClientAPIImpl.getAllSubscriptionGroup(anyString(), anyLong())).thenReturn(subscriptionGroupWrapper);
    String topicListConfig = "topicListConfig";
    when(mQClientAPIImpl.getKVConfigValue(anyString(), anyString(), anyLong())).thenReturn(topicListConfig);
    KVTable kvTable = new KVTable();
    HashMap<String, String> kv = new HashMap<>();
    kv.put("broker-name", "broker-one");
    kv.put("cluster-name", "default-cluster");
    kvTable.setTable(kv);
    when(mQClientAPIImpl.getKVListByNamespace(anyString(), anyLong())).thenReturn(kvTable);
    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);
    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    connections.add(new Connection());
    consumerConnection.setConnectionSet(connections);
    consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>());
    consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection);
    ProducerConnection producerConnection = new ProducerConnection();
    Connection connection = new Connection();
    connection.setClientAddr("127.0.0.1:9898");
    connection.setClientId("PID_12345");
    HashSet<Connection> connectionSet = new HashSet<Connection>();
    connectionSet.add(connection);
    producerConnection.setConnectionSet(connectionSet);
    when(mQClientAPIImpl.getProducerConnectionList(anyString(), anyString(), anyLong())).thenReturn(producerConnection);
    when(mQClientAPIImpl.wipeWritePermOfBroker(anyString(), anyString(), anyLong())).thenReturn(6);
    TopicStatsTable topicStatsTable = new TopicStatsTable();
    topicStatsTable.setOffsetTable(new HashMap<MessageQueue, TopicOffset>());
    Map<String, Map<MessageQueue, Long>> consumerStatus = new HashMap<>();
    when(mQClientAPIImpl.invokeBrokerToGetConsumerStatus(anyString(), anyString(), anyString(), anyString(), anyLong())).thenReturn(consumerStatus);
    List<QueueTimeSpan> queueTimeSpanList = new ArrayList<>();
    when(mQClientAPIImpl.queryConsumeTimeSpan(anyString(), anyString(), anyString(), anyLong())).thenReturn(queueTimeSpanList);
    ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo();
    consumerRunningInfo.setJstack("test");
    consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>());
    consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>());
    consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>());
    when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicStatsTable(org.apache.rocketmq.common.admin.TopicStatsTable) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) List(java.util.List) ArrayList(java.util.ArrayList) ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) HashSet(java.util.HashSet) KVTable(org.apache.rocketmq.common.protocol.body.KVTable) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumeStatus(org.apache.rocketmq.common.protocol.body.ConsumeStatus) QueueTimeSpan(org.apache.rocketmq.common.protocol.body.QueueTimeSpan) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) Field(java.lang.reflect.Field) TopicOffset(org.apache.rocketmq.common.admin.TopicOffset) ConsumerRunningInfo(org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ProcessQueueInfo(org.apache.rocketmq.common.protocol.body.ProcessQueueInfo) Connection(org.apache.rocketmq.common.protocol.body.Connection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) BeforeClass(org.junit.BeforeClass)

Example 7 with OffsetWrapper

use of org.apache.rocketmq.common.admin.OffsetWrapper in project rocketmq by apache.

the class ConsumerProgressSubCommandTest method init.

@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingException, MQClientException, MQBrokerException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);
    TopicRouteData topicRouteData = new TopicRouteData();
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    topicRouteData.setQueueDatas(new ArrayList<QueueData>());
    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) HashMap(java.util.HashMap) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) Field(java.lang.reflect.Field) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArrayList(java.util.ArrayList) List(java.util.List) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) DefaultMQAdminExtImpl(org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl) BeforeClass(org.junit.BeforeClass)

Example 8 with OffsetWrapper

use of org.apache.rocketmq.common.admin.OffsetWrapper in project rocketmq by apache.

the class GroupConsumeInfo method execute.

@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();
        if (commandLine.hasOption('g')) {
            String consumerGroup = commandLine.getOptionValue('g').trim();
            ConsumeStats consumeStats = defaultMQAdminExt.examineConsumeStats(consumerGroup);
            List<MessageQueue> mqList = new LinkedList<MessageQueue>();
            mqList.addAll(consumeStats.getOffsetTable().keySet());
            Collections.sort(mqList);
            Map<MessageQueue, String> messageQueueAllocationResult = getMessageQueueAllocationResult(defaultMQAdminExt, consumerGroup);
            System.out.printf("%-32s  %-32s  %-4s  %-20s  %-20s  %-20s %-20s  %s%n", "#Topic", "#Broker Name", "#QID", "#Broker Offset", "#Consumer Offset", "#Client IP", "#Diff", "#LastTime");
            long diffTotal = 0L;
            for (MessageQueue mq : mqList) {
                OffsetWrapper offsetWrapper = consumeStats.getOffsetTable().get(mq);
                long diff = offsetWrapper.getBrokerOffset() - offsetWrapper.getConsumerOffset();
                diffTotal += diff;
                String lastTime = "";
                try {
                    lastTime = UtilAll.formatDate(new Date(offsetWrapper.getLastTimestamp()), UtilAll.YYYY_MM_DD_HH_MM_SS);
                } catch (Exception e) {
                }
                String clientIP = messageQueueAllocationResult.get(mq);
                System.out.printf("%-32s  %-32s  %-4d  %-20d  %-20d  %-20s %-20d  %s%n", UtilAll.frontStringAtLeast(mq.getTopic(), 32), UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), offsetWrapper.getBrokerOffset(), offsetWrapper.getConsumerOffset(), null != clientIP ? clientIP : "NA", diff, lastTime);
            }
            System.out.printf("%n");
            System.out.printf("Consume TPS: %s%n", consumeStats.getConsumeTps());
            System.out.printf("Diff Total: %d%n", diffTotal);
        } else {
            System.out.printf("%-32s  %-6s  %-24s %-5s  %-14s  %-7s  %s%n", "#Group", "#Count", "#Version", "#Type", "#Model", "#TPS", "#Diff Total");
            TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
            for (String topic : topicList.getTopicList()) {
                if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
                    String consumerGroup = topic.substring(MixAll.RETRY_GROUP_TOPIC_PREFIX.length());
                    try {
                        ConsumeStats consumeStats = null;
                        try {
                            consumeStats = defaultMQAdminExt.examineConsumeStats(consumerGroup);
                        } catch (Exception e) {
                            log.warn("examineConsumeStats exception, " + consumerGroup, e);
                        }
                        ConsumerConnection cc = null;
                        try {
                            cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
                        } catch (Exception e) {
                            log.warn("examineConsumerConnectionInfo exception, " + consumerGroup, e);
                        }
                        GroupConsumeInfo groupConsumeInfo = new GroupConsumeInfo();
                        groupConsumeInfo.setGroup(consumerGroup);
                        if (consumeStats != null) {
                            groupConsumeInfo.setConsumeTps((int) consumeStats.getConsumeTps());
                            groupConsumeInfo.setDiffTotal(consumeStats.computeTotalDiff());
                        }
                        if (cc != null) {
                            groupConsumeInfo.setCount(cc.getConnectionSet().size());
                            groupConsumeInfo.setMessageModel(cc.getMessageModel());
                            groupConsumeInfo.setConsumeType(cc.getConsumeType());
                            groupConsumeInfo.setVersion(cc.computeMinVersion());
                        }
                        System.out.printf("%-32s  %-6d  %-24s %-5s  %-14s  %-7d  %d%n", UtilAll.frontStringAtLeast(groupConsumeInfo.getGroup(), 32), groupConsumeInfo.getCount(), groupConsumeInfo.getCount() > 0 ? groupConsumeInfo.versionDesc() : "OFFLINE", groupConsumeInfo.consumeTypeDesc(), groupConsumeInfo.messageModelDesc(), groupConsumeInfo.getConsumeTps(), groupConsumeInfo.getDiffTotal());
                    } catch (Exception e) {
                        log.warn("examineConsumeStats or examineConsumerConnectionInfo exception, " + consumerGroup, e);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) LinkedList(java.util.LinkedList) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) Date(java.util.Date) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt)

Example 9 with OffsetWrapper

use of org.apache.rocketmq.common.admin.OffsetWrapper in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtImpl method consumed.

public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    ConsumeStats cstats = this.examineConsumeStats(group);
    ClusterInfo ci = this.examineBrokerClusterInfo();
    Iterator<Entry<MessageQueue, OffsetWrapper>> it = cstats.getOffsetTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, OffsetWrapper> next = it.next();
        MessageQueue mq = next.getKey();
        if (mq.getTopic().equals(msg.getTopic()) && mq.getQueueId() == msg.getQueueId()) {
            BrokerData brokerData = ci.getBrokerAddrTable().get(mq.getBrokerName());
            if (brokerData != null) {
                String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (addr.equals(RemotingUtil.socketAddress2String(msg.getStoreHost()))) {
                    if (next.getValue().getConsumerOffset() > msg.getQueueOffset()) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) Entry(java.util.Map.Entry) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper)

Example 10 with OffsetWrapper

use of org.apache.rocketmq.common.admin.OffsetWrapper in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BrokerConsumeStatsSubCommad method execute.

@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();
    }
}
Also used : ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) LinkedList(java.util.LinkedList) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) Date(java.util.Date) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) List(java.util.List) ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) LinkedList(java.util.LinkedList) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) Map(java.util.Map)

Aggregations

OffsetWrapper (org.apache.rocketmq.common.admin.OffsetWrapper)22 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)22 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)20 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)10 List (java.util.List)10 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)10 Map (java.util.Map)8 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)8 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)8 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)8 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)8 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)8 Field (java.lang.reflect.Field)6 HashSet (java.util.HashSet)6 Entry (java.util.Map.Entry)6 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)6 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)6 ConsumeStatsList (org.apache.rocketmq.common.protocol.body.ConsumeStatsList)6 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)6