Java Code Examples for org.apache.rocketmq.common.TopicConfig#getReadQueueNums()

The following examples show how to use org.apache.rocketmq.common.TopicConfig#getReadQueueNums() . 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: BrokerController.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway, boolean forceRegister) {
    TopicConfigSerializeWrapper topicConfigWrapper = this.getTopicConfigManager().buildTopicConfigSerializeWrapper();

    if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
        || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
        ConcurrentHashMap<String, TopicConfig> topicConfigTable = new ConcurrentHashMap<String, TopicConfig>();
        for (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) {
            TopicConfig tmp =
                new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
                    this.brokerConfig.getBrokerPermission());
            topicConfigTable.put(topicConfig.getTopicName(), tmp);
        }
        topicConfigWrapper.setTopicConfigTable(topicConfigTable);
    }

    if (forceRegister || needRegister(this.brokerConfig.getBrokerClusterName(),
        this.getBrokerAddr(),
        this.brokerConfig.getBrokerName(),
        this.brokerConfig.getBrokerId(),
        this.brokerConfig.getRegisterBrokerTimeoutMills())) {
        doRegisterBrokerAll(checkOrderConfig, oneway, topicConfigWrapper);
    }
}
 
Example 2
Source File: TransactionalMessageBridge.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 根据topic获取消费队列
 * @param topic topic
 * @return ;
 */
public Set<MessageQueue> fetchMessageQueues(String topic) {

    Set<MessageQueue> mqSet = new HashSet<>();
    TopicConfig topicConfig = selectTopicConfig(topic);

    if (topicConfig != null && topicConfig.getReadQueueNums() > 0) {
        for (int i = 0; i < topicConfig.getReadQueueNums(); i++) {
            MessageQueue mq = new MessageQueue();
            mq.setTopic(topic);
            mq.setBrokerName(brokerController.getBrokerConfig().getBrokerName());
            mq.setQueueId(i);
            mqSet.add(mq);
        }
    }
    return mqSet;
}
 
Example 3
Source File: AdjustQueueNumStrategy.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
public boolean isCanAdjustReadQueueSize(String topic, int scaleQueueSize) {
    TopicConfig topicConfig = deFiBrokerController.getTopicConfigManager().getTopicConfigTable().get(topic);
    if (topicConfig != null) {
        for (int qId = scaleQueueSize; qId < topicConfig.getReadQueueNums(); qId++) {
            long maxOffsetInConsumeQueue = deFiBrokerController.getMessageStore().getMaxOffsetInQueue(topic, qId);
            long lastMsgTime = deFiBrokerController.getMessageStore().getMessageStoreTimeStamp(topic, qId, maxOffsetInConsumeQueue - 1);
            long diff = System.currentTimeMillis() - lastMsgTime;
            if (diff < 60 * 1000) {
                log.info("adjust queue num, still new message in within {} ms, default threshold 60000 ms", System.currentTimeMillis() - lastMsgTime);
                return false;
            }

            Set<String> topicConsumeByWho = this.deFiBrokerController.getConsumerManager().queryTopicConsumeByWho(topic);
            Set<String> groupInOffset = this.deFiBrokerController.getConsumerOffsetManager().whichGroupByTopic(topic);
            if (groupInOffset != null && !groupInOffset.isEmpty()) {
                topicConsumeByWho.addAll(groupInOffset);
            }
            boolean allConsumed = isAllMessageConsumed(topic, topicConsumeByWho, qId);
            if (!allConsumed) {
                return false;
            }
        }
        return true;
    }
    return false;
}
 
Example 4
Source File: BrokerController.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 注册Broker
 * @param checkOrderConfig ;
 * @param oneway ;
 * @param forceRegister 是否强制注册
 */
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway, boolean forceRegister) {
    TopicConfigSerializeWrapper topicConfigWrapper = this.getTopicConfigManager().buildTopicConfigSerializeWrapper();

    //如果当前的Broker不可写或者不可读
    if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
        || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {

        ConcurrentHashMap<String, TopicConfig> topicConfigTable = new ConcurrentHashMap<>();
        for (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) {
            TopicConfig tmp =
                new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
                    this.brokerConfig.getBrokerPermission());
            topicConfigTable.put(topicConfig.getTopicName(), tmp);
        }
        topicConfigWrapper.setTopicConfigTable(topicConfigTable);
    }

    //如果是强制注册,或者需要注册,就执行注册NameServer
    if (forceRegister || needRegister(this.brokerConfig.getBrokerClusterName(),
        this.getBrokerAddr(),
        this.brokerConfig.getBrokerName(),
        this.brokerConfig.getBrokerId(),
        this.brokerConfig.getRegisterBrokerTimeoutMills())) {
        doRegisterBrokerAll(checkOrderConfig, oneway, topicConfigWrapper);
    }
}
 
Example 5
Source File: TransactionalMessageBridge.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public Set<MessageQueue> fetchMessageQueues(String topic) {
    Set<MessageQueue> mqSet = new HashSet<>();
    TopicConfig topicConfig = selectTopicConfig(topic);
    if (topicConfig != null && topicConfig.getReadQueueNums() > 0) {
        for (int i = 0; i < topicConfig.getReadQueueNums(); i++) {
            MessageQueue mq = new MessageQueue();
            mq.setTopic(topic);
            mq.setBrokerName(brokerController.getBrokerConfig().getBrokerName());
            mq.setQueueId(i);
            mqSet.add(mq);
        }
    }
    return mqSet;
}
 
Example 6
Source File: TransactionalMessageBridge.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public Set<MessageQueue> fetchMessageQueues(String topic) {
    Set<MessageQueue> mqSet = new HashSet<>();
    TopicConfig topicConfig = selectTopicConfig(topic);
    if (topicConfig != null && topicConfig.getReadQueueNums() > 0) {
        for (int i = 0; i < topicConfig.getReadQueueNums(); i++) {
            MessageQueue mq = new MessageQueue();
            mq.setTopic(topic);
            mq.setBrokerName(brokerController.getBrokerConfig().getBrokerName());
            mq.setQueueId(i);
            mqSet.add(mq);
        }
    }
    return mqSet;
}
 
Example 7
Source File: BrokerController.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway, boolean forceRegister) {
//        包装topic配置信息
        TopicConfigSerializeWrapper topicConfigWrapper = this.getTopicConfigManager().buildTopicConfigSerializeWrapper();

//        如果没有读写权限
        if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
            || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
            ConcurrentHashMap<String, TopicConfig> topicConfigTable = new ConcurrentHashMap<String, TopicConfig>();
            for (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) {
                TopicConfig tmp =
                    new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
                        this.brokerConfig.getBrokerPermission());
                topicConfigTable.put(topicConfig.getTopicName(), tmp);
            }
            topicConfigWrapper.setTopicConfigTable(topicConfigTable);
        }

//        判断broker集群是否需要注册=》
        if (forceRegister || needRegister(this.brokerConfig.getBrokerClusterName(),
            this.getBrokerAddr(),
            this.brokerConfig.getBrokerName(),
            this.brokerConfig.getBrokerId(),
            this.brokerConfig.getRegisterBrokerTimeoutMills())) {
//            向所有的broker注册topic配置信息 =》
            doRegisterBrokerAll(checkOrderConfig, oneway, topicConfigWrapper);
        }
    }
 
Example 8
Source File: DeFiAdminBrokerProcessor.java    From DeFiBus with Apache License 2.0 4 votes vote down vote up
private RemotingCommand getConsumeStatsV2(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetConsumeStatsRequestHeader requestHeader =
        (GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class);

    DeFiBusConsumeStats consumeStats = new DeFiBusConsumeStats();

    Set<String> topics = new HashSet<String>();
    if (UtilAll.isBlank(requestHeader.getTopic())) {
        topics = this.deFiBrokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getConsumerGroup());
    } else {
        topics.add(requestHeader.getTopic());
    }

    for (String topic : topics) {
        TopicConfig topicConfig = this.deFiBrokerController.getTopicConfigManager().selectTopicConfig(topic);
        if (null == topicConfig) {
            log.warn("consumeStats, topic config not exist, {}", topic);
            continue;
        }

        {
            SubscriptionData findSubscriptionData =
                this.deFiBrokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic);

            if (null == findSubscriptionData //
                && this.deFiBrokerController.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.deFiBrokerController.getBrokerConfig().getBrokerName());
            mq.setQueueId(i);

            DeFiBusOffsetWrapper offsetWrapper = new DeFiBusOffsetWrapper();

            long brokerOffset = this.deFiBrokerController.getMessageStore().getMaxOffsetInQueue(topic, i);
            if (brokerOffset < 0)
                brokerOffset = 0;

            long consumerOffset = this.deFiBrokerController.getConsumerOffsetManager().queryOffset(//
                requestHeader.getConsumerGroup(), //
                topic, //
                i);
            if (consumerOffset < 0)
                consumerOffset = 0;

            long lastDeliverOffset = this.deFiBrokerController.getConsumeQueueManager().queryDeliverOffset(//
                requestHeader.getConsumerGroup(), //
                topic, //
                i);
            if (lastDeliverOffset < consumerOffset) {
                lastDeliverOffset = consumerOffset;
                this.deFiBrokerController.getConsumeQueueManager().recordLastDeliverOffset(requestHeader.getConsumerGroup(), //
                    topic, i, consumerOffset);
            }

            offsetWrapper.setBrokerOffset(brokerOffset);
            offsetWrapper.setConsumerOffset(consumerOffset);
            offsetWrapper.setLastDeliverOffset(lastDeliverOffset);

            long timeOffset = consumerOffset - 1;
            if (timeOffset >= 0) {
                long lastTimestamp = this.deFiBrokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset);
                if (lastTimestamp > 0) {
                    offsetWrapper.setLastTimestamp(lastTimestamp);
                }
            }

            consumeStats.getOffsetTable().put(mq, offsetWrapper);
        }

        double consumeTps = this.deFiBrokerController.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 9
Source File: AdjustQueueNumStrategy.java    From DeFiBus with Apache License 2.0 4 votes vote down vote up
private void adjustReadQueueNumByConsumerCount(String topic, long delayMills, AdjustType mode) {
    Runnable scaleQueueTask = new Runnable() {
        private int alreadyRetryTimes = 0;

        @Override
        public void run() {
            TopicConfig topicConfig = deFiBrokerController.getTopicConfigManager().getTopicConfigTable().get(topic);
            if (topicConfig != null) {
                synchronized (topicConfig.getTopicName()) {

                    //query again to ensure it's newest
                    topicConfig = deFiBrokerController.getTopicConfigManager().getTopicConfigTable().get(topic);
                    int adjustReadQueueSize = adjustQueueSizeByMaxConsumerCount(topic);

                    if (AdjustType.INCREASE_QUEUE_NUM == mode && adjustReadQueueSize < topicConfig.getReadQueueNums()) {
                        log.info("can not decrease read queue size to {} for [{}], prev: {}, {}", adjustReadQueueSize, topic, topicConfig.getReadQueueNums(), mode);
                        return;
                    }
                    if (AdjustType.DECREASE_QUEUE_NUM == mode && adjustReadQueueSize > topicConfig.getReadQueueNums()) {
                        log.info("can not increase read queue size to {} for [{}], prev: {}, {}", adjustReadQueueSize, topic, topicConfig.getReadQueueNums(), mode);
                        return;
                    }

                    if (adjustReadQueueSize != topicConfig.getReadQueueNums()) {
                        log.info("try adjust read queue size to {} for [{}], prev: {}, {}", adjustReadQueueSize, topic, topicConfig.getReadQueueNums(), mode);
                        if (adjustReadQueueSize < topicConfig.getWriteQueueNums()) {
                            log.info("adjust read queues to {} for [{}] fail. read queue size can't less than write queue size[{}]. {}",
                                adjustReadQueueSize, topic, topicConfig.getWriteQueueNums(), mode);
                            return;
                        }
                        boolean canAdjustReadQueueSize = isCanAdjustReadQueueSize(topic, adjustReadQueueSize);
                        if (canAdjustReadQueueSize) {
                            if (adjustReadQueueSize >= topicConfig.getWriteQueueNums() && adjustReadQueueSize < 1024) {
                                if (mode == AdjustType.INCREASE_QUEUE_NUM && adjustReadQueueSize > 4) {
                                    log.warn("[NOTIFY]auto adjust queues more than 4 for [{}]. {}", topic, mode);
                                }
                                TopicConfig topicConfigNew = generateNewTopicConfig(topicConfig, topicConfig.getWriteQueueNums(), adjustReadQueueSize);
                                deFiBrokerController.getTopicConfigManager().updateTopicConfig(topicConfigNew);
                                deFiBrokerController.registerBrokerAll(true, false, true);
                                notifyWhenTopicConfigChange(topic);
                            } else if (adjustReadQueueSize >= 1024) {
                                log.warn("[NOTIFY]auto adjust queue num is limited to 1024 for [{}]. {}", topic, mode);
                            }
                        } else {
                            if (this.alreadyRetryTimes < deFiBrokerController.getDeFiBusBrokerConfig().getScaleQueueRetryTimesMax()) {
                                log.info("try adjust read queue size to {} for [{}] fail. retry times: [{}]. {}", adjustReadQueueSize, topic, this.alreadyRetryTimes, mode);
                                this.alreadyRetryTimes++;
                                scheduleAdjustQueueSizeTask(this, delayMills, topic, mode);
                                log.info("adjustQueueSizeScheduleExecutor queued: {}", autoScaleQueueSizeExecutorService.getQueue().size());
                            } else {
                                log.warn("try adjust read queue size to {} for [{}] fail. ignore after retry {} times. {}", adjustReadQueueSize, topic, this.alreadyRetryTimes, mode);
                            }
                        }
                    } else {
                        log.info("no need to adjust read queue size for [{}]. now [w:{}/r:{}]. {}", topic, topicConfig.getWriteQueueNums(), topicConfig.getReadQueueNums(), mode);
                    }
                }
            } else {
                log.info("skip adjust read queue size for [{}]. topicConfig is null.", topic);
            }
        }
    };
    this.scheduleAdjustQueueSizeTask(scaleQueueTask, delayMills, topic, mode);
}
 
Example 10
Source File: AdjustQueueNumStrategy.java    From DeFiBus with Apache License 2.0 4 votes vote down vote up
private void adjustWriteQueueNumByConsumerCount(String topic, long delayMills, AdjustType mode) {
    Runnable scaleTask = new Runnable() {
        @Override
        public void run() {
            TopicConfig topicConfig = deFiBrokerController.getTopicConfigManager().getTopicConfigTable().get(topic);
            if (topicConfig != null) {
                synchronized (topicConfig.getTopicName()) {

                    //query again to ensure it's newest
                    topicConfig = deFiBrokerController.getTopicConfigManager().getTopicConfigTable().get(topic);
                    int adjustWriteQueueSize = adjustQueueSizeByMaxConsumerCount(topic);

                    if (AdjustType.INCREASE_QUEUE_NUM == mode && adjustWriteQueueSize < topicConfig.getWriteQueueNums()) {
                        log.info("can not decrease write queue size to {} for [{}], prev: {}, {}", adjustWriteQueueSize, topic, topicConfig.getWriteQueueNums(), mode);
                        return;
                    }
                    if (AdjustType.DECREASE_QUEUE_NUM == mode && adjustWriteQueueSize > topicConfig.getWriteQueueNums()) {
                        log.info("can not increase write queue size to {} for [{}], prev: {}, {}", adjustWriteQueueSize, topic, topicConfig.getWriteQueueNums(), mode);
                        return;
                    }

                    if (adjustWriteQueueSize != topicConfig.getWriteQueueNums()) {
                        log.info("try adjust write queue size to {} for [{}], prev: {}. {}", adjustWriteQueueSize, topic, topicConfig.getWriteQueueNums(), mode);
                        if (adjustWriteQueueSize >= 0 && adjustWriteQueueSize <= topicConfig.getReadQueueNums()) {
                            TopicConfig topicConfigNew = generateNewTopicConfig(topicConfig, adjustWriteQueueSize, topicConfig.getReadQueueNums());
                            deFiBrokerController.getTopicConfigManager().updateTopicConfig(topicConfigNew);
                            deFiBrokerController.registerBrokerAll(true, false, true);
                            notifyWhenTopicConfigChange(topic);
                        } else {
                            log.info("adjust write queues to {} for [{}] fail. target write queue size can't less than 0 or greater than read queue size[{}]. mode: {}",
                                adjustWriteQueueSize, topic, topicConfig.getReadQueueNums(), mode);
                        }
                    } else {
                        log.info("no need to adjust write queue size for [{}]. now [w:{}/r:{}]. {}", topic, topicConfig.getWriteQueueNums(), topicConfig.getReadQueueNums(), mode);
                    }
                }
            } else {
                log.info("skip adjust write queue size for [{}]. topicConfig is null.", topic);
            }
        }
    };
    this.scheduleAdjustQueueSizeTask(scaleTask, delayMills, topic, mode);
}
 
Example 11
Source File: AdminBrokerProcessor.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
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=》
            topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getConsumerGroup());
        } else {
            topics.add(requestHeader.getTopic());
        }

        for (String topic : topics) {
//            按topic名称从本地缓存中获取topic配置信息
            TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
            if (null == topicConfig) {
                log.warn("consumeStats, topic config not exist, {}", topic);
                continue;
            }

            {
//                按消费组和topic获取订阅数据=》
                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;
                }
            }

//            默认读队列数量16
            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();

//                按topic和queueId查询broker的offset=》
                long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i);
                if (brokerOffset < 0)
                    brokerOffset = 0;

//                按消费组、topic、queueId查询消费者的offset=》
                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);
            }

//            按消费组和topic获取消费者的tps
            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 12
Source File: QueueListeningMonitor.java    From DeFiBus with Apache License 2.0 4 votes vote down vote up
private void scanQueueMissListening() {
    if (!deFiBrokerController.getDeFiBusBrokerConfig().isCheckQueueListening()) {
        return;
    }

    for (Map.Entry<String, ConsumerGroupInfo> entry : deFiBrokerController.getConsumerManager().getConsumerTable().entrySet()) {
        String groupName = entry.getKey();
        ConsumerGroupInfo groupInfo = entry.getValue();
        if (groupInfo.getMessageModel().equals(MessageModel.BROADCASTING)) {
            continue;
        }

        boolean rebalanceRecently = false;

        Map<String/*topic*/, Integer/*listening queue count*/> listenQueueCountMap = new HashMap<>();

        groupLoop:
        for (Channel channel : groupInfo.getChannelInfoTable().keySet()) {
            ClientChannelInfo clientChannelInfo = groupInfo.getChannelInfoTable().get(channel);

            if (clientChannelInfo.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
                log.warn("The Consumer <{}> Version <{}> too low to finish, please upgrade it to V3_1_8_SNAPSHOT",
                    clientChannelInfo.getClientId(),
                    MQVersion.getVersionDesc(clientChannelInfo.getVersion()));
                continue;
            }

            ConsumerRunningInfo runningInfo = callConsumer(groupName, clientChannelInfo);

            if (runningInfo == null) {
                log.warn("[MISS LISTENING] clientId <{}> group <{}>, runningInfo is null", clientChannelInfo.getClientId(), groupName);
                continue;
            }

            for (SubscriptionData subscriptionData : runningInfo.getSubscriptionSet()) {
                if (System.currentTimeMillis() - subscriptionData.getSubVersion() < 2 * 60 * 1000) {
                    rebalanceRecently = true;
                    break groupLoop;
                }
            }

            //miss listening when subscribing a topic but not listening any queue
            if (runningInfo.getSubscriptionSet() != null && !runningInfo.getSubscriptionSet().isEmpty() && runningInfo.getMqTable().isEmpty()) {
                log.warn("[MISS LISTENING] clientId <{}> group <{}>, listening none queue", clientChannelInfo.getClientId(), groupName);
                continue;
            }

            String analyzeProcessQueue = ConsumerRunningInfo.analyzeProcessQueue(clientChannelInfo.getClientId(), runningInfo);
            if (StringUtils.isNotEmpty(analyzeProcessQueue)) {
                log.warn("[BLOCKED SUBSCRIBER] " + analyzeProcessQueue);
            }

            Set<MessageQueue> mqSet = runningInfo.getMqTable().keySet();
            for (MessageQueue mq : mqSet) {
                if (!mq.getBrokerName().equals(this.deFiBrokerController.getBrokerConfig().getBrokerName())) {
                    continue;
                }
                Integer listenQueueNum = listenQueueCountMap.get(mq.getTopic());
                if (listenQueueNum == null)
                    listenQueueNum = 0;

                listenQueueCountMap.put(mq.getTopic(), listenQueueNum + 1);
            }
        }

        //skip if do rebalance in 2 min
        if (!rebalanceRecently) {
            for (String topic : listenQueueCountMap.keySet()) {
                TopicConfig topicConfig = this.deFiBrokerController.getTopicConfigManager().selectTopicConfig(topic);
                if (null == topicConfig) {
                    continue;
                }
                int queueNum = topicConfig.getReadQueueNums();
                int listeningNum = listenQueueCountMap.get(topic);
                if (queueNum != listeningNum) {
                    log.warn("[MISS LISTENING] group <{}>, topic={}, queueNum={}, listeningNum={}", groupName, topic, queueNum, listeningNum);
                }
            }
        }

    }
}
 
Example 13
Source File: BrokerController.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway) {
    if (!roleChangeState.equals(RoleChangeState.SUCCESS)) {
        log.warn("role change state:{}, not register broker to name server", roleChangeState);
        return;
    }

    TopicConfigSerializeWrapper topicConfigWrapper = this.getTopicConfigManager().buildTopicConfigSerializeWrapper();

    if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
        || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
        ConcurrentHashMap<String, TopicConfig> topicConfigTable = new ConcurrentHashMap<String, TopicConfig>();
        for (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) {
            TopicConfig tmp =
                new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
                    this.brokerConfig.getBrokerPermission());
            topicConfigTable.put(topicConfig.getTopicName(), tmp);
        }
        topicConfigWrapper.setTopicConfigTable(topicConfigTable);
    }

    RegisterBrokerResult registerBrokerResult = null;
    for (int i = 0; i < 3; i++) {
        registerBrokerResult = this.brokerOuterAPI.registerBrokerAll(
            this.brokerConfig.getBrokerClusterName(),
            this.getBrokerAddr(),
            this.brokerConfig.getBrokerName(),
            this.brokerConfig.getBrokerId(),
            this.getHAServerAddr(),
            this.messageStore.getMaxPhyOffset(),
            this.term,
            topicConfigWrapper,
            this.filterServerManager.buildNewFilterServerList(),
            oneway,
            this.brokerConfig.getRegisterBrokerTimeoutMills());

        if (registerBrokerResult != null && registerBrokerResult.getKvTable() != null
            && registerBrokerResult.getKvTable().getTable().containsKey(ConfigName.REGISTER_RESPONSE_KV_KEY_TERM)) {
            long termResponse = Long.valueOf(registerBrokerResult.getKvTable().getTable().get(ConfigName.REGISTER_RESPONSE_KV_KEY_TERM));
            if (termResponse > this.term) {
                log.info("term update, new term:{}, old Term:{}, register again", termResponse, this.term);
                this.term = termResponse;
            } else {
                break;
            }
        } else {
            break;
        }
    }

    if (registerBrokerResult != null) {
        if (this.updateMasterHAServerAddrPeriodically && registerBrokerResult.getHaServerAddr() != null) {
            this.messageStore.updateHaMasterAddress(registerBrokerResult.getHaServerAddr());
        }

        this.slaveSynchronize.setMasterAddr(registerBrokerResult.getMasterAddr());

        if (checkOrderConfig) {
            this.getTopicConfigManager().updateOrderTopicConfig(registerBrokerResult.getKvTable());
        }
    }
}
 
Example 14
Source File: AdminBrokerProcessor.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
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().getMaxOffsetInQueue(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 15
Source File: BrokerController.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway) {
    if (!roleChangeState.equals(RoleChangeState.SUCCESS)) {
        log.warn("role change state:{}, not register broker to name server", roleChangeState);
        return;
    }

    TopicConfigSerializeWrapper topicConfigWrapper = this.getTopicConfigManager().buildTopicConfigSerializeWrapper();

    if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
        || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
        ConcurrentHashMap<String, TopicConfig> topicConfigTable = new ConcurrentHashMap<String, TopicConfig>();
        for (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) {
            TopicConfig tmp =
                new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
                    this.brokerConfig.getBrokerPermission());
            topicConfigTable.put(topicConfig.getTopicName(), tmp);
        }
        topicConfigWrapper.setTopicConfigTable(topicConfigTable);
    }

    RegisterBrokerResult registerBrokerResult = null;
    for (int i = 0; i < 3; i++) {
        registerBrokerResult = this.brokerOuterAPI.registerBrokerAll(
            this.brokerConfig.getBrokerClusterName(),
            this.getBrokerAddr(),
            this.brokerConfig.getBrokerName(),
            this.brokerConfig.getBrokerId(),
            this.getHAServerAddr(),
            this.messageStore.getMaxPhyOffset(),
            this.term,
            topicConfigWrapper,
            this.filterServerManager.buildNewFilterServerList(),
            oneway,
            this.brokerConfig.getRegisterBrokerTimeoutMills());

        if (registerBrokerResult != null && registerBrokerResult.getKvTable() != null
            && registerBrokerResult.getKvTable().getTable().containsKey(ConfigName.REGISTER_RESPONSE_KV_KEY_TERM)) {
            long termResponse = Long.valueOf(registerBrokerResult.getKvTable().getTable().get(ConfigName.REGISTER_RESPONSE_KV_KEY_TERM));
            if (termResponse > this.term) {
                log.info("term update, new term:{}, old Term:{}, register again", termResponse, this.term);
                this.term = termResponse;
            } else {
                break;
            }
        } else {
            break;
        }
    }

    if (registerBrokerResult != null) {
        if (this.updateMasterHAServerAddrPeriodically && registerBrokerResult.getHaServerAddr() != null) {
            this.messageStore.updateHaMasterAddress(registerBrokerResult.getHaServerAddr());
        }

        this.slaveSynchronize.setMasterAddr(registerBrokerResult.getMasterAddr());

        if (checkOrderConfig) {
            this.getTopicConfigManager().updateOrderTopicConfig(registerBrokerResult.getKvTable());
        }
    }
}
 
Example 16
Source File: AdminBrokerProcessor.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
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().getMaxOffsetInQueue(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 17
Source File: BrokerController.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway) {
	//构建topicConfigSerializeWrapper
    TopicConfigSerializeWrapper topicConfigWrapper = this.getTopicConfigManager().buildTopicConfigSerializeWrapper();

    if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
        || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
        ConcurrentHashMap<String, TopicConfig> topicConfigTable = new ConcurrentHashMap<String, TopicConfig>();
        for (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) {
            TopicConfig tmp =
                new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
                    this.brokerConfig.getBrokerPermission());
            topicConfigTable.put(topicConfig.getTopicName(), tmp);
        }
        topicConfigWrapper.setTopicConfigTable(topicConfigTable);
    }

    //向 NameServer注册 Broker
    RegisterBrokerResult registerBrokerResult = this.brokerOuterAPI.registerBrokerAll(
        this.brokerConfig.getBrokerClusterName(),
        this.getBrokerAddr(),
        this.brokerConfig.getBrokerName(),
        this.brokerConfig.getBrokerId(),
        this.getHAServerAddr(),
        topicConfigWrapper,
        this.filterServerManager.buildNewFilterServerList(),
        oneway,
        this.brokerConfig.getRegisterBrokerTimeoutMills());

    if (registerBrokerResult != null) {
    	//根据 updateMasterHAServerAddrPeriodically 标注位判断是否需要更新主用Broker地址 
        if (this.updateMasterHAServerAddrPeriodically && registerBrokerResult.getHaServerAddr() != null) {
            this.messageStore.updateHaMasterAddress(registerBrokerResult.getHaServerAddr());
        }

        //用 NameServer 返回的 MasterAddr 值更新 SlaveSynchronize.setMasterAddr值,用于主备 Broker 同步 Config 文件使用
        this.slaveSynchronize.setMasterAddr(registerBrokerResult.getMasterAddr());

        if (checkOrderConfig) {
            this.getTopicConfigManager().updateOrderTopicConfig(registerBrokerResult.getKvTable());
        }
    }
}
 
Example 18
Source File: AdminBrokerProcessor.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
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().getMaxOffsetInQueue(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 19
Source File: AdminBrokerProcessor.java    From rocketmq_trans_message with Apache License 2.0 4 votes vote down vote up
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 20
Source File: AdminBrokerProcessor.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
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().getMaxOffsetInQueue(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;
}