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;
}
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();
}
}
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);
}
Aggregations