Search in sources :

Example 1 with OracleSource

use of com.ververica.cdc.connectors.oracle.OracleSource in project dlink by DataLinkDC.

the class OracleCDCBuilder method build.

@Override
public DataStreamSource<String> build(StreamExecutionEnvironment env) {
    Properties properties = new Properties();
    for (Map.Entry<String, String> entry : config.getDebezium().entrySet()) {
        if (Asserts.isNotNullString(entry.getKey()) && Asserts.isNotNullString(entry.getValue())) {
            properties.setProperty(entry.getKey(), entry.getValue());
        }
    }
    OracleSource.Builder<String> sourceBuilder = OracleSource.<String>builder().hostname(config.getHostname()).port(config.getPort()).username(config.getUsername()).password(config.getPassword()).database(config.getDatabase());
    String schema = config.getSchema();
    if (Asserts.isNotNullString(schema)) {
        String[] schemas = schema.split(FlinkParamConstant.SPLIT);
        sourceBuilder.schemaList(schemas);
    } else {
        sourceBuilder.schemaList(new String[0]);
    }
    List<String> schemaTableNameList = config.getSchemaTableNameList();
    if (Asserts.isNotNullCollection(schemaTableNameList)) {
        sourceBuilder.tableList(schemaTableNameList.toArray(new String[schemaTableNameList.size()]));
    } else {
        sourceBuilder.tableList(new String[0]);
    }
    sourceBuilder.deserializer(new JsonDebeziumDeserializationSchema());
    sourceBuilder.debeziumProperties(properties);
    if (Asserts.isNotNullString(config.getStartupMode())) {
        switch(config.getStartupMode().toLowerCase()) {
            case "initial":
                sourceBuilder.startupOptions(StartupOptions.initial());
                break;
            case "latest-offset":
                sourceBuilder.startupOptions(StartupOptions.latest());
                break;
        }
    } else {
        sourceBuilder.startupOptions(StartupOptions.latest());
    }
    return env.addSource(sourceBuilder.build(), "Oracle CDC Source");
}
Also used : OracleSource(com.ververica.cdc.connectors.oracle.OracleSource) Properties(java.util.Properties) JsonDebeziumDeserializationSchema(com.ververica.cdc.debezium.JsonDebeziumDeserializationSchema) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with OracleSource

use of com.ververica.cdc.connectors.oracle.OracleSource in project flink-cdc-connectors by ververica.

the class OracleTableSource 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 = RowDataDebeziumDeserializeSchema.newBuilder().setPhysicalRowType(physicalDataType).setMetadataConverters(metadataConverters).setResultTypeInfo(typeInfo).setUserDefinedConverterFactory(OracleDeserializationConverterFactory.instance()).build();
    OracleSource.Builder<RowData> builder = OracleSource.<RowData>builder().hostname(hostname).port(port).database(database).tableList(schemaName + "." + tableName).schemaList(schemaName).username(username).password(password).debeziumProperties(dbzProperties).startupOptions(startupOptions).deserializer(deserializer);
    DebeziumSourceFunction<RowData> sourceFunction = builder.build();
    return SourceFunctionProvider.of(sourceFunction, false);
}
Also used : RowData(org.apache.flink.table.data.RowData) MetadataConverter(com.ververica.cdc.debezium.table.MetadataConverter) OracleSource(com.ververica.cdc.connectors.oracle.OracleSource) RowType(org.apache.flink.table.types.logical.RowType)

Example 3 with OracleSource

use of com.ververica.cdc.connectors.oracle.OracleSource in project plugins by qlangtech.

the class FlinkCDCOracleSourceFunction method start.

@Override
public JobExecutionResult start(TargetResName channalName, IDataxReader dataSource, List<ISelectedTab> tabs, IDataxProcessor dataXProcessor) throws MQConsumeException {
    try {
        BasicDataXRdbmsReader reader = (BasicDataXRdbmsReader) dataSource;
        BasicDataSourceFactory f = (BasicDataSourceFactory) reader.getDataSourceFactory();
        SourceChannel sourceChannel = new SourceChannel(SourceChannel.getSourceFunction(f, (tab) -> tab.getTabName(), tabs, (dbHost, dbs, tbs, debeziumProperties) -> {
            return dbs.stream().map((databaseName) -> {
                SourceFunction<DTO> sourceFunction = OracleSource.<DTO>builder().hostname(dbHost).debeziumProperties(debeziumProperties).port(f.port).startupOptions(sourceFactory.getStartupOptions()).database(// monitor XE database
                StringUtils.upperCase(f.dbName)).tableList(// monitor products table
                tbs.toArray(new String[tbs.size()])).username(f.getUserName()).password(f.getPassword()).deserializer(// converts SourceRecord to JSON String
                new TISDeserializationSchema()).build();
                return new ReaderSource(dbHost + ":" + f.port + "_" + databaseName, sourceFunction);
            }).collect(Collectors.toList());
        }));
        for (ISelectedTab tab : tabs) {
            sourceChannel.addFocusTab(tab.getName());
        }
        return (JobExecutionResult) getConsumerHandle().consume(channalName, sourceChannel, dataXProcessor);
    } catch (Exception e) {
        throw new MQConsumeException(e.getMessage(), e);
    }
}
Also used : MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) IConsumerHandle(com.qlangtech.tis.async.message.client.consumer.IConsumerHandle) StringUtils(org.apache.commons.lang.StringUtils) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) OracleSource(com.ververica.cdc.connectors.oracle.OracleSource) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) DTO(com.qlangtech.tis.realtime.transfer.DTO) TISDeserializationSchema(com.qlangtech.plugins.incr.flink.cdc.TISDeserializationSchema) Collectors(java.util.stream.Collectors) BasicDataSourceFactory(com.qlangtech.tis.plugin.ds.BasicDataSourceFactory) SourceChannel(com.qlangtech.plugins.incr.flink.cdc.SourceChannel) ReaderSource(com.qlangtech.tis.realtime.ReaderSource) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) List(java.util.List) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) IDataxReader(com.qlangtech.tis.datax.IDataxReader) IAsyncMsgDeserialize(com.qlangtech.tis.async.message.client.consumer.IAsyncMsgDeserialize) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) IMQListener(com.qlangtech.tis.async.message.client.consumer.IMQListener) BasicDataSourceFactory(com.qlangtech.tis.plugin.ds.BasicDataSourceFactory) SourceChannel(com.qlangtech.plugins.incr.flink.cdc.SourceChannel) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) TISDeserializationSchema(com.qlangtech.plugins.incr.flink.cdc.TISDeserializationSchema) MQConsumeException(com.qlangtech.tis.async.message.client.consumer.MQConsumeException) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader) ReaderSource(com.qlangtech.tis.realtime.ReaderSource) DTO(com.qlangtech.tis.realtime.transfer.DTO)

Aggregations

OracleSource (com.ververica.cdc.connectors.oracle.OracleSource)3 SourceChannel (com.qlangtech.plugins.incr.flink.cdc.SourceChannel)1 TISDeserializationSchema (com.qlangtech.plugins.incr.flink.cdc.TISDeserializationSchema)1 IAsyncMsgDeserialize (com.qlangtech.tis.async.message.client.consumer.IAsyncMsgDeserialize)1 IConsumerHandle (com.qlangtech.tis.async.message.client.consumer.IConsumerHandle)1 IMQListener (com.qlangtech.tis.async.message.client.consumer.IMQListener)1 MQConsumeException (com.qlangtech.tis.async.message.client.consumer.MQConsumeException)1 TargetResName (com.qlangtech.tis.coredefine.module.action.TargetResName)1 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)1 IDataxReader (com.qlangtech.tis.datax.IDataxReader)1 BasicDataXRdbmsReader (com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader)1 BasicDataSourceFactory (com.qlangtech.tis.plugin.ds.BasicDataSourceFactory)1 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)1 ReaderSource (com.qlangtech.tis.realtime.ReaderSource)1 DTO (com.qlangtech.tis.realtime.transfer.DTO)1 JsonDebeziumDeserializationSchema (com.ververica.cdc.debezium.JsonDebeziumDeserializationSchema)1 MetadataConverter (com.ververica.cdc.debezium.table.MetadataConverter)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1