Class DebeziumIO
read() and a Debezium configuration.
Quick Overview
This class lets Beam users connect to their existing Debezium implementations in an easy way.
Any Kafka connector supported by Debezium should work fine with this IO.
The following connectors were tested and worked well in some simple scenarios:
- MySQL
- PostgreSQL
- SQLServer
- DB2
Usage example
Support is currently experimental. One of the known issues is that the connector does not preserve the offset on a worker crash or restart, causing it to retrieve all the data from the beginning again. See Issue #28248 for details.
Connect to a Debezium - MySQL database and run a Pipeline
private static final ConnectorConfiguration mySqlConnectorConfig = ConnectorConfiguration
.create()
.withUsername("uname")
.withPassword("pwd123")
.withHostName("127.0.0.1")
.withPort("3306")
.withConnectorClass(MySqlConnector.class)
.withConnectionProperty("database.server.id", "184054")
.withConnectionProperty("database.server.name", "serverid")
.withConnectionProperty("database.history", DebeziumSDFDatabaseHistory.class.getName())
.withConnectionProperty("include.schema.changes", "false");
PipelineOptions options = PipelineOptionsFactory.create();
Pipeline p = Pipeline.create(options);
p.apply(DebeziumIO.read()
.withConnectorConfiguration(mySqlConnectorConfig)
.withFormatFunction(new SourceRecordJson.SourceRecordJsonMapper())
).setCoder(StringUtf8Coder.of());
p.run().waitUntilFinish();
In this example we are using KafkaSourceConsumerFn.DebeziumSDFDatabaseHistory to
handle the Database history.
Dependencies
User may work with any of the supported Debezium Connectors above mentioned
See Debezium Connectors for more info.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA POJO describing a Debezium configuration.static classImplementation ofread(). -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> DebeziumIO.Read<T> read()Read data from a Debezium source.static DebeziumIO.Read<String> Read data from Debezium source and convert a KafkaSourceRecordinto a JSON string usingSourceRecordJson.SourceRecordJsonMapperas default function mapper.
-
Method Details
-
read
Read data from a Debezium source.- Type Parameters:
T- Type of the data to be read.
-
readAsJson
Read data from Debezium source and convert a KafkaSourceRecordinto a JSON string usingSourceRecordJson.SourceRecordJsonMapperas default function mapper.- Returns:
- Reader object of String.
-