[db2] Fix stream api example in db2 doc. (#1725)

Co-authored-by: gongzhongqiang <gongzhongqiang@gigacloudtech.com>
pull/1718/head
gongzhongqiang 2 years ago committed by GitHub
parent c9bb718d57
commit e1085a33e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -50,8 +50,8 @@ Notes
### Not support BOOLEAN type in SQL Replication on Db2 ### Not support BOOLEAN type in SQL Replication on Db2
Only snapshots can be taken from tables with BOOLEAN type columns. Currently SQL Replication on Db2 does not support BOOLEAN, so Debezium can not perform CDC on those tables. Only snapshots can be taken from tables with BOOLEAN type columns. Currently, SQL Replication on Db2 does not support BOOLEAN, so Debezium can not perform CDC on those tables.
Consider using a different type. Consider using another type to replace BOOLEAN type.
How to create a Db2 CDC table How to create a Db2 CDC table
@ -203,36 +203,36 @@ _Note: the mechanism of `scan.startup.mode` option relying on Debezium's `snapsh
### DataStream Source ### DataStream Source
```java ```java
import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.kafka.connect.source.SourceRecord; import org.apache.flink.streaming.api.functions.source.SourceFunction;
import com.ververica.cdc.debezium.JsonDebeziumDeserializationSchema; import com.ververica.cdc.debezium.JsonDebeziumDeserializationSchema;
import com.ververica.cdc.connectors.db2.Db2Source;
public class Db2SourceExample { public class Db2SourceExample {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Db2Source<SourceRecord> db2Source = Db2Source.<SourceRecord>builder() SourceFunction<String> db2Source =
.hostname("yourHostname") Db2Source.<String>builder()
.port(yourPort) .hostname("yourHostname")
.database("yourDatabaseName") // set captured database .port(50000)
.tableList("yourSchemaName.yourTableName") // set captured table .database("yourDatabaseName") // set captured database
.username("yourUsername") .tableList("yourSchemaName.yourTableName") // set captured table
.password("yourPassword") .username("yourUsername")
.deserializer(new JsonDebeziumDeserializationSchema()) // converts SourceRecord to JSON String .password("yourPassword")
.build(); .deserializer(
new JsonDebeziumDeserializationSchema()) // converts SourceRecord to
// JSON String
.build();
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
// enable checkpoint // enable checkpoint
env.enableCheckpointing(3000); env.enableCheckpointing(3000);
env env.addSource(db2Source)
.fromSource(db2Source, WatermarkStrategy.noWatermarks(), "Db2 Source") .print()
// set 4 parallel source tasks .setParallelism(1); // use parallelism 1 for sink to keep message ordering
.setParallelism(1)
.print().setParallelism(1); // use parallelism 1 for sink to keep message ordering
env.execute("Print Db2 Snapshot + Binlog"); env.execute("Print Db2 Snapshot + Change Stream");
} }
} }
``` ```

@ -294,7 +294,7 @@ public class Db2SourceTest extends Db2TestBase {
assertDelete(records.get(0), "ID", 1001); assertDelete(records.get(0), "ID", 1001);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Step-6: trigger checkpoint-2 to make sure we can continue to to further checkpoints // Step-6: trigger checkpoint-2 to make sure we can continue to further checkpoints
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
synchronized (sourceContext3.getCheckpointLock()) { synchronized (sourceContext3.getCheckpointLock()) {
// checkpoint 3 // checkpoint 3

Loading…
Cancel
Save