Search in sources :

Example 1 with TaskTopicInfo

use of org.apache.rocketmq.connect.jdbc.config.TaskTopicInfo 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

HashSet (java.util.HashSet)1 MQClientException (org.apache.rocketmq.client.exception.MQClientException)1 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)1 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)1 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)1 SinkDbConnectorConfig (org.apache.rocketmq.connect.jdbc.config.SinkDbConnectorConfig)1 TaskTopicInfo (org.apache.rocketmq.connect.jdbc.config.TaskTopicInfo)1