Search in sources :

Example 1 with SinkDbConnectorConfig

use of org.apache.rocketmq.connect.jdbc.config.SinkDbConnectorConfig in project rocketmq-externals by apache.

the class JdbcSinkConnector method startMQAdminTools.

private synchronized void startMQAdminTools() {
    if (!configValid || adminStarted) {
        return;
    }
    RPCHook rpcHook = null;
    this.srcMQAdminExt = new DefaultMQAdminExt(rpcHook);
    this.srcMQAdminExt.setNamesrvAddr(((SinkDbConnectorConfig) this.dbConnectorConfig).getSrcNamesrvs());
    this.srcMQAdminExt.setAdminExtGroup(Utils.createGroupName(ConstDefine.JDBC_CONNECTOR_ADMIN_PREFIX));
    this.srcMQAdminExt.setInstanceName(Utils.createInstanceName(((SinkDbConnectorConfig) this.dbConnectorConfig).getSrcNamesrvs()));
    try {
        this.srcMQAdminExt.start();
        log.info("RocketMQ srcMQAdminExt started");
    } catch (MQClientException e) {
        log.error("Replicator start failed for `srcMQAdminExt` exception.", e);
    }
    adminStarted = true;
}
Also used : SinkDbConnectorConfig(org.apache.rocketmq.connect.jdbc.config.SinkDbConnectorConfig) RPCHook(org.apache.rocketmq.remoting.RPCHook) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 2 with SinkDbConnectorConfig

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

Example 3 with SinkDbConnectorConfig

use of org.apache.rocketmq.connect.jdbc.config.SinkDbConnectorConfig in project rocketmq-externals by apache.

the class JdbcSinkConnector method taskConfigs.

@Override
public List<KeyValue> taskConfigs() {
    log.info("List.start");
    if (!configValid) {
        return new ArrayList<KeyValue>();
    }
    startMQAdminTools();
    buildRoute();
    TaskDivideConfig tdc = new TaskDivideConfig(this.dbConnectorConfig.getDbUrl(), this.dbConnectorConfig.getDbPort(), this.dbConnectorConfig.getDbUserName(), this.dbConnectorConfig.getDbPassword(), this.dbConnectorConfig.getConverter(), DataType.COMMON_MESSAGE.ordinal(), this.dbConnectorConfig.getTaskParallelism(), this.dbConnectorConfig.getMode());
    ((SinkDbConnectorConfig) this.dbConnectorConfig).setTopicRouteMap(topicRouteMap);
    return this.dbConnectorConfig.getTaskDivideStrategy().divide(this.dbConnectorConfig, tdc);
}
Also used : ArrayList(java.util.ArrayList) SinkDbConnectorConfig(org.apache.rocketmq.connect.jdbc.config.SinkDbConnectorConfig) TaskDivideConfig(org.apache.rocketmq.connect.jdbc.config.TaskDivideConfig)

Aggregations

SinkDbConnectorConfig (org.apache.rocketmq.connect.jdbc.config.SinkDbConnectorConfig)3 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)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 TaskDivideConfig (org.apache.rocketmq.connect.jdbc.config.TaskDivideConfig)1 TaskTopicInfo (org.apache.rocketmq.connect.jdbc.config.TaskTopicInfo)1 RPCHook (org.apache.rocketmq.remoting.RPCHook)1 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)1