MysqlCDC数据获取代码

public static MySqlSource getMysqlSource(String db,
String tab) {
Properties props = new Properties();
props.setProperty("useSSL", "false");
props.setProperty("allowPublicKeyRetrieval", "true");
MySqlSource mySqlSource = MySqlSource.builder()
.hostname(Constant.MYSQL_HOST)
.port(Constant.MYSQL_PORT)
.databaseList(db) // set captured database, If you need to synchronize the whole database, Please set tableList to ".*".
.tableList(db + "." + tab) // set captured table
.username(Constant.MYSQL_USER_NAME)
.password(Constant.MYSQL_PASSWORD)
.jdbcProperties(props)
.deserializer(new JsonDebeziumDeserializationSchema()) // converts SourceRecord to JSON String
.startupOptions(StartupOptions.initial()) // 默认值: initial 第一次启动读取所有数据(快照), 然后通过 binlog 实时监控变化数据
.build();
return mySqlSource;
}

posted @ 2025-02-01 11:02  自在现实  阅读(25)  评论(0)    收藏  举报