Flink CDC 实现Postgres变更捕获

记录快速接入 postgres cdc

工具选型

  1. Postgres 10+
  2. flink 1.13.3 , flink-connector-postgres-cdc 2.2.0
  3. Flink-CDC文档
    flink-connector Github
    Github官网的README记录是支持9.6的,不过使用Postgres 9.6的docker容器测试时部分SQL语法报错了,猜测是flink-connector-postgres-cdc依赖过高的问题,Postgres 9.6可以降低至2.0 or 2.1,此处使用Postgres 10+的容器进行测试。

过程

本地环境参考之前MySQL CDC
Postgres 归档日志配置,配置文件处于Postgres Data目录的postgresql.conf
更改 WRITE-AHEAD LOG 部分然后重启

wal_level = logical                    # minimal, replica, or logical
                                        # (change requires restart)

flink 程序参考

		Properties properties = new Properties();
        properties.setProperty("snapshot.mode", "initial");
        properties.setProperty("decimal.handling.mode", "double"); //debezium 小数转换处理策略
        properties.setProperty("database.serverTimezone", "GMT+8"); //debezium 配置以database. 开头的属性将被传递给jdbc url
        
        SourceFunction<String> sourceFunction = PostgreSQLSource.<String>builder()
                .hostname("192.168.31.233")
                .port(5432)
                .database("postgres") // monitor postgres database
                .schemaList("public")  // monitor inventory schema
                .tableList("public.t_table") // monitor products table
                .username("root")
                .password("123456")
                .decodingPluginName("pgoutput") // pg解码插件
                .slotName("t_table_slot") // 复制槽名称 不能重复
                .deserializer(new JsonDebeziumDeserializationSchema()) // converts SourceRecord to JSON String
                .debeziumProperties(properties)
                .build();

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env
                .addSource(sourceFunction)
                .print().setParallelism(1); // use parallelism 1 for sink to keep message ordering

        env.execute();

没啥可说的,source 出来操作完通过skin适配不同的目标库实现实时流。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三千烦恼丝xzh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值