Search in sources :

Example 46 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.

the class DashboardCollectTask method collectTopic.

@Scheduled(cron = "30 0/1 * * * ?")
@MultiMQAdminCmdMethod(timeoutMillis = 5000)
public void collectTopic() {
    if (!rmqConfigure.isEnableDashBoardCollect()) {
        return;
    }
    Date date = new Date();
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        TopicList topicList = mqAdminExt.fetchAllTopicList();
        Set<String> topicSet = topicList.getTopicList();
        for (String topic : topicSet) {
            if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                continue;
            }
            TopicRouteData topicRouteData = mqAdminExt.examineTopicRouteInfo(topic);
            GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic);
            double inTPS = 0;
            long inMsgCntToday = 0;
            double outTPS = 0;
            long outMsgCntToday = 0;
            for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (masterAddr != null) {
                    try {
                        stopwatch.start();
                        log.info("start time: {}", stopwatch.toString());
                        BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic);
                        stopwatch.stop();
                        log.info("stop time : {}", stopwatch.toString());
                        stopwatch.reset();
                        inTPS += bsd.getStatsMinute().getTps();
                        inMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                    } catch (Exception e) {
                    // throw Throwables.propagate(e);
                    }
                }
            }
            if (groupList != null && !groupList.getGroupList().isEmpty()) {
                for (String group : groupList.getGroupList()) {
                    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                        String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                        if (masterAddr != null) {
                            try {
                                String statsKey = String.format("%s@%s", topic, group);
                                BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey);
                                outTPS += bsd.getStatsMinute().getTps();
                                outMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                            } catch (Exception e) {
                            // throw Throwables.propagate(e);
                            }
                        }
                    }
                }
            }
            List<String> list;
            try {
                list = dashboardCollectService.getTopicMap().get(topic);
            } catch (ExecutionException e) {
                throw Throwables.propagate(e);
            }
            if (null == list) {
                list = Lists.newArrayList();
            }
            list.add(date.getTime() + "," + new BigDecimal(inTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + inMsgCntToday + "," + new BigDecimal(outTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + outMsgCntToday);
            dashboardCollectService.getTopicMap().put(topic, list);
        }
        log.debug("Topic Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getTopicMap().asMap()));
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Stopwatch(com.google.common.base.Stopwatch) Date(java.util.Date) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BigDecimal(java.math.BigDecimal) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) ExecutionException(java.util.concurrent.ExecutionException) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData) Scheduled(org.springframework.scheduling.annotation.Scheduled) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 47 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.

the class HudiSinkConnector method buildRoute.

public void buildRoute() {
    String srcCluster = this.sinkConnectConfig.getSrcCluster();
    try {
        for (String topic : this.sinkConnectConfig.getWhiteList()) {
            // different from BrokerData with cluster field, which can ensure the brokerData is from expected cluster.
            // QueueData use brokerName as unique info on cluster of rocketmq. so when we want to get QueueData of
            // expected cluster, we should get brokerNames of expected cluster, and then filter queueDatas.
            List<BrokerData> brokerList = Utils.examineBrokerData(this.srcMQAdminExt, topic, srcCluster);
            Set<String> brokerNameSet = new HashSet<String>();
            for (BrokerData b : brokerList) {
                brokerNameSet.add(b.getBrokerName());
            }
            TopicRouteData topicRouteData = srcMQAdminExt.examineTopicRouteInfo(topic);
            if (!topicRouteMap.containsKey(topic)) {
                topicRouteMap.put(topic, new HashSet<>(16));
            }
            for (QueueData qd : topicRouteData.getQueueDatas()) {
                if (brokerNameSet.contains(qd.getBrokerName())) {
                    for (int i = 0; i < qd.getReadQueueNums(); i++) {
                        MessageQueue taskTopicInfo = new MessageQueue(topic, qd.getBrokerName(), i);
                        topicRouteMap.get(topic).add(taskTopicInfo);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("Fetch topic list error.", e);
    } finally {
        srcMQAdminExt.shutdown();
    }
}
Also used : MessageQueue(org.apache.rocketmq.common.message.MessageQueue) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) MQClientException(org.apache.rocketmq.client.exception.MQClientException) HashSet(java.util.HashSet) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 48 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.

the class Utils method examineBrokerData.

public static List<BrokerData> examineBrokerData(DefaultMQAdminExt defaultMQAdminExt, String topic, String cluster) throws RemotingException, MQClientException, InterruptedException {
    List<BrokerData> brokerList = new ArrayList<>();
    TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
    if (topicRouteData.getBrokerDatas() != null) {
        for (BrokerData broker : topicRouteData.getBrokerDatas()) {
            if (StringUtils.equals(broker.getCluster(), cluster)) {
                brokerList.add(broker);
            }
        }
    }
    return brokerList;
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) ArrayList(java.util.ArrayList) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 49 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.

the class Utils method examineBrokerData.

public static List<BrokerData> examineBrokerData(DefaultMQAdminExt defaultMQAdminExt, String topic, String cluster) throws RemotingException, MQClientException, InterruptedException {
    List<BrokerData> brokerList = new ArrayList<>();
    TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
    if (topicRouteData.getBrokerDatas() != null) {
        for (BrokerData broker : topicRouteData.getBrokerDatas()) {
            if (StringUtils.equals(broker.getCluster(), cluster)) {
                brokerList.add(broker);
            }
        }
    }
    return brokerList;
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) ArrayList(java.util.ArrayList) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 50 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData in project rocketmq-externals by apache.

the class JdbcSinkConnector method buildRoute.

public void buildRoute() {
    String srcCluster = ((SinkDbConnectorConfig) this.dbConnectorConfig).getSrcCluster();
    try {
        for (String topic : ((SinkDbConnectorConfig) this.dbConnectorConfig).getWhiteList()) {
            // different from BrokerData with cluster field, which can ensure the brokerData is from expected cluster.
            // QueueData use brokerName as unique info on cluster of rocketmq. so when we want to get QueueData of
            // expected cluster, we should get brokerNames of expected cluster, and then filter queueDatas.
            List<BrokerData> brokerList = Utils.examineBrokerData(this.srcMQAdminExt, topic, srcCluster);
            Set<String> brokerNameSet = new HashSet<String>();
            for (BrokerData b : brokerList) {
                brokerNameSet.add(b.getBrokerName());
            }
            TopicRouteData topicRouteData = srcMQAdminExt.examineTopicRouteInfo(topic);
            if (!topicRouteMap.containsKey(topic)) {
                topicRouteMap.put(topic, new HashSet<>(16));
            }
            for (QueueData qd : topicRouteData.getQueueDatas()) {
                if (brokerNameSet.contains(qd.getBrokerName())) {
                    for (int i = 0; i < qd.getReadQueueNums(); i++) {
                        TaskTopicInfo taskTopicInfo = new TaskTopicInfo(topic, qd.getBrokerName(), i, null);
                        topicRouteMap.get(topic).add(taskTopicInfo);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("Fetch topic list error.", e);
    } finally {
        srcMQAdminExt.shutdown();
    }
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) TaskTopicInfo(org.apache.rocketmq.connect.jdbc.config.TaskTopicInfo) SinkDbConnectorConfig(org.apache.rocketmq.connect.jdbc.config.SinkDbConnectorConfig) MQClientException(org.apache.rocketmq.client.exception.MQClientException) HashSet(java.util.HashSet) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Aggregations

TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)92 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)65 ArrayList (java.util.ArrayList)25 MQClientException (org.apache.rocketmq.client.exception.MQClientException)25 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)25 HashMap (java.util.HashMap)22 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)20 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)18 List (java.util.List)16 HashSet (java.util.HashSet)13 Entry (java.util.Map.Entry)12 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)12 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)11 Field (java.lang.reflect.Field)10 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)10 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)10 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)10 DefaultMQAdminExtImpl (org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl)10