use of com.ververica.cdc.connectors.mongodb.MongoDBSource in project plugins by qlangtech.
the class FlinkCDCMongoDBSourceFunction method start.
@Override
public JobExecutionResult start(TargetResName dataxName, IDataxReader dataSource, List<ISelectedTab> tabs, IDataxProcessor dataXProcessor) throws MQConsumeException {
try {
DataXMongodbReader mongoReader = (DataXMongodbReader) dataSource;
MangoDBDataSourceFactory dsFactory = mongoReader.getDsFactory();
List<ReaderSource> sourceFunctions = Lists.newArrayList();
MongoDBSource.Builder<DTO> builder = MongoDBSource.<DTO>builder().hosts(dsFactory.address).database(dsFactory.dbName).collection(mongoReader.collectionName).connectionOptions(sourceFactory.connectionOptions).errorsTolerance(sourceFactory.errorsTolerance).username(dsFactory.getUserName()).password(dsFactory.getPassword()).deserializer(new TISDeserializationSchema());
if (sourceFactory.errorsLogEnable != null) {
builder.errorsLogEnable(sourceFactory.errorsLogEnable);
}
if (sourceFactory.copyExisting != null) {
builder.copyExisting(sourceFactory.copyExisting);
}
if (sourceFactory.copyExistingMaxThreads != null) {
builder.copyExistingMaxThreads(sourceFactory.copyExistingMaxThreads);
}
if (sourceFactory.copyExistingQueueSize != null) {
builder.copyExistingMaxThreads(sourceFactory.copyExistingQueueSize);
}
if (sourceFactory.pollMaxBatchSize != null) {
builder.copyExistingMaxThreads(sourceFactory.pollMaxBatchSize);
}
if (sourceFactory.pollAwaitTimeMillis != null) {
builder.copyExistingMaxThreads(sourceFactory.pollAwaitTimeMillis);
}
if (sourceFactory.heartbeatIntervalMillis != null) {
builder.copyExistingMaxThreads(sourceFactory.heartbeatIntervalMillis);
}
SourceFunction<DTO> source = builder.build();
// MongoDBSource.<DTO>builder()
// .hosts(dsFactory.address)
// .database(dsFactory.dbName)
// .collection(mongoReader.collectionName)
// .connectionOptions(sourceFactory.connectionOptions)
// .errorsTolerance(sourceFactory.errorsTolerance)
// .errorsLogEnable(sourceFactory.errorsLogEnable)
// .copyExisting(sourceFactory.copyExisting)
// .copyExistingPipeline(sourceFactory.copyExistingPipeline)
// .copyExistingMaxThreads(sourceFactory.copyExistingMaxThreads)
// .copyExistingQueueSize(sourceFactory.copyExistingQueueSize)
// .pollMaxBatchSize(sourceFactory.pollMaxBatchSize)
// .pollAwaitTimeMillis(sourceFactory.pollAwaitTimeMillis)
// .heartbeatIntervalMillis(sourceFactory.heartbeatIntervalMillis)
// //.port(dsFactory.port)
// // .databaseList(dbs.toArray(new String[dbs.size()])) // monitor all tables under inventory database
// // .tableList(tbs.toArray(new String[tbs.size()]))
// .username(dsFactory.getUserName())
// .password(dsFactory.getPassword())
// // .startupOptions(sourceFactory.getStartupOptions())
// //.debeziumProperties(debeziumProperties)
// .deserializer(new TISDeserializationSchema()) // converts SourceRecord to JSON String
// .build();
sourceFunctions.add(new ReaderSource(dsFactory.address + "_" + dsFactory.dbName + "_" + mongoReader.collectionName, source));
SourceChannel sourceChannel = new SourceChannel(sourceFunctions);
for (ISelectedTab tab : tabs) {
sourceChannel.addFocusTab(tab.getName());
}
return (JobExecutionResult) getConsumerHandle().consume(dataxName, sourceChannel, dataXProcessor);
} catch (Exception e) {
throw new MQConsumeException(e.getMessage(), e);
}
}
use of com.ververica.cdc.connectors.mongodb.MongoDBSource in project flink-cdc-connectors by ververica.
the class MongoDBTableSource method getScanRuntimeProvider.
@Override
public ScanRuntimeProvider getScanRuntimeProvider(ScanContext scanContext) {
RowType physicalDataType = (RowType) physicalSchema.toPhysicalRowDataType().getLogicalType();
MetadataConverter[] metadataConverters = getMetadataConverters();
TypeInformation<RowData> typeInfo = scanContext.createTypeInformation(producedDataType);
DebeziumDeserializationSchema<RowData> deserializer = new MongoDBConnectorDeserializationSchema(physicalDataType, metadataConverters, typeInfo, localTimeZone);
MongoDBSource.Builder<RowData> builder = MongoDBSource.<RowData>builder().hosts(hosts).deserializer(deserializer);
if (StringUtils.isNotEmpty(database) && StringUtils.isNotEmpty(collection)) {
// explicitly specified database and collection.
if (!containsRegexMetaCharacters(database) && !containsRegexMetaCharacters(collection)) {
checkDatabaseNameValidity(database);
checkCollectionNameValidity(collection);
builder.databaseList(database);
builder.collectionList(database + "." + collection);
} else {
builder.databaseList(database);
builder.collectionList(collection);
}
} else if (StringUtils.isNotEmpty(database)) {
builder.databaseList(database);
} else if (StringUtils.isNotEmpty(collection)) {
builder.collectionList(collection);
} else {
// Watching all changes on the cluster by default, we do nothing here
}
Optional.ofNullable(username).ifPresent(builder::username);
Optional.ofNullable(password).ifPresent(builder::password);
Optional.ofNullable(connectionOptions).ifPresent(builder::connectionOptions);
Optional.ofNullable(errorsLogEnable).ifPresent(builder::errorsLogEnable);
Optional.ofNullable(errorsTolerance).ifPresent(builder::errorsTolerance);
Optional.ofNullable(copyExisting).ifPresent(builder::copyExisting);
Optional.ofNullable(copyExistingPipeline).ifPresent(builder::copyExistingPipeline);
Optional.ofNullable(copyExistingMaxThreads).ifPresent(builder::copyExistingMaxThreads);
Optional.ofNullable(copyExistingQueueSize).ifPresent(builder::copyExistingQueueSize);
Optional.ofNullable(pollMaxBatchSize).ifPresent(builder::pollMaxBatchSize);
Optional.ofNullable(pollAwaitTimeMillis).ifPresent(builder::pollAwaitTimeMillis);
Optional.ofNullable(heartbeatIntervalMillis).ifPresent(builder::heartbeatIntervalMillis);
DebeziumSourceFunction<RowData> sourceFunction = builder.build();
return SourceFunctionProvider.of(sourceFunction, false);
}
Aggregations