Flink CDC 数据处理
看看资讯 / 100+人浏览
注意:免费节点订阅链接已更新至 2026-10-25,点击查看详情
简介
官方地址
https://ververica.github.io/flink-cdc-connectors/master/content/connectors/mysql-cdc.htmlFlink CDC 是Flink 的一个源连接器,用于获取不同数据库中变更的数据,Flink CDC Connectors 集成了 Debezium
#debezium相关 https://github.com/debezium/debezium- Supported Connectors
Database | Version |
MySQL | Database: 5.7, 8.0.x |
PostgreSQL | Database: 9.6, 10, 11, 12 |
MongoDB | Database: 3.6, 4.x, 5.0 |
Oracle | Database: 11, 12, 19 |
- Suported Flink Versions
Flink CDC Connector Version | Flink Version |
1.0.0 | 1.11.* |
1.1.0 | 1.11.* |
1.2.0 | 1.12.* |
1.3.0 | 1.12.* |
1.4.0 | 1.13.* |
2.0.* | 1.13.* |
2.1.* | 1.13.* |
DataStream Api
完整代码示例:
https://gitee.com/sxuboss_admin/FlinkDemoAll.gitdependency
<dependency> <groupId>com.alibaba.ververica</groupId> <artifactId>flink-connector-mysql-cdc</artifactId> <version>1.3.0</version> </dependency>code
package com.bbx.flink.dataStream_api_all; import com.alibaba.ververica.cdc.connectors.mysql.MySQLSource; import com.alibaba.ververica.cdc.connectors.mysql.table.StartupOptions; import com.alibaba.ververica.cdc.debezium.DebeziumSourceFunction; import com.alibaba.ververica.cdc.debezium.StringDebeziumDeserializationSchema; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; public class FlinkCDCDemo { public static void main(String [] args) throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DebeziumSourceFunction<String> sourceFunction = MySQLSource.<String>builder() .hostname("192.168.10.7") .port(3306) .username("root") .password("000000") .databaseList("maxwell_test1", "maxwell_test2") //DB .tableList("maxwell_test1.test1", "maxwell_test1.test2", "maxwell_test2.test3") //表 .deserializer(new StringDebeziumDeserializationSchema()) //反序列化-此处可以自定义反序列化--详见下面自定义反序列化,利用 StringDebeziumDeserializationSchema 可以查看能获取到的信息,然后在进行自定义获取 .startupOptions(StartupOptions.initial()) .build(); env.addSource(sourceFunction) .setParallelism(1) .print(); env.execute("print CDC"); } }创建数据库,maxwell_test1,maxwell_test2,同步创建表test1,test2,test3,并开启binlong,相关参考 Maxwell,
自定义反序列化
package com.bbx.flink.dataStream_api_all.CDC; import cn.hutool.json.JSONObject; import com.alibaba.ververica.cdc.debezium.DebeziumDeserializationSchema; import io.debezium.data.Envelope; import org.apache.flink.api.common.typeinfo.BasicTypeInfo; import org.apache.flink.api.common.typeinfo.TypeInformation; import org.apache.flink.util.Collector; import org.apache.kafka.connect.data.Field; import org.apache.kafka.connect.data.Schema; import org.apache.kafka.connect.data.Struct; import org.apache.kafka.connect.source.SourceRecord; import java.util.List; /** * 自定义 debezium 反序列化 */ public class CustomerDebeziumDeserializationSchema implements DebeziumDeserializationSchema<String> { private static final long serialVersionUID = 9042745421910624673L; @Override public TypeInformation<String> getProducedType() { return BasicTypeInfo.STRING_TYPE_INFO; } /** * { * "db":"", * "table":"", * "before":{"id:"","name":""...}, * "after":{"id:"","name":""...}, * "op":"" * } * * @param sourceRecord * @param collector * @throws Exception */ @Override public void deserialize(SourceRecord sourceRecord, Collector<String> collector) throws Exception { JSONObject jsonObject = new JSONObject(); //获取 db 和table String topic = sourceRecord.topic(); String[] split = topic.split("\\."); //获取before,after Struct value = (Struct) sourceRecord.value(); Object before = getStructInfo(value, "before"); Object after = getStructInfo(value, "after"); //获取操作类型 Envelope.Operation operation = Envelope.operationFor(sourceRecord); jsonObject.set("db", split[0]) .set("table", split[1]) .set("op", operation) .set("before", before) .set("after", after); collector.collect(jsonObject.toString()); } public Object getStructInfo(Struct struct,String name){ Struct tmpStruct = struct.getStruct(name); JSONObject jsonObject = new JSONObject(); if (tmpStruct != null) { Schema schema = tmpStruct.schema(); List<Field> fields = schema.fields(); fields.forEach(i -> { jsonObject.set(i.name(), tmpStruct.get(i)); }); } return jsonObject; } }Table Api & SQL
code
package com.bbx.flink.dataStream_api_all.CDC; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; public class FlinkCDCTableDemo { public static void main(String [] args) throws Exception { //执行环境 StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(1); //获取table Env StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); String test1Sql=" CREATE TABLE test1 (\n" + " id INT,\n" + " name STRING\n" + " ) WITH (\n" + " 'connector' = 'mysql-cdc',\n" + " 'hostname' = '192.168.10.7',\n" + " 'port' = '3306',\n" + " 'username' = 'root',\n" + " 'password' = '123456',\n" + " 'database-name' = 'maxwell_test1',\n" + " 'table-name' = 'test1')"; tableEnv.executeSql(test1Sql); String querySQl = "select * from test1"; tableEnv.executeSql(querySQl).print(); } }
版权声明:
作者: FreeClashNode
链接: https://www.freeclashnode.com/news/article-1652.htm
来源: www.freeclashnode.com
文章版权归作者所有,未经允许请勿转载。
免费节点实时更新
热门文章
- 10月1日免费节点分享|18M/S,Clash节点/V2ray节点/Singbox节点/SSR节点|免费上网梯子每天更新
- 10月2日免费节点分享|22.8M/S,Singbox节点/Shadowrocket节点/Clash节点/V2ray节点|免费上网梯子每天更新
- 10月3日免费节点分享|20.1M/S,SSR节点/Singbox节点/V2ray节点/Clash节点|免费上网梯子每天更新
- 9月30日免费节点分享|19.1M/S,Clash节点/V2ray节点/SSR节点/Singbox节点|免费上网梯子每天更新
- 10月6日免费节点分享|19.2M/S,V2ray节点/Singbox节点/Shadowrocket节点/Clash节点|免费上网梯子每天更新
- 10月8日免费节点分享|22.5M/S,V2ray节点/Singbox节点/Clash节点/Shadowrocket节点|免费上网梯子每天更新
- 10月11日免费节点分享|18.6M/S,V2ray节点/Clash节点/SSR节点/Singbox节点|免费上网梯子每天更新
- 10月5日免费节点分享|19.9M/S,Singbox节点/Clash节点/V2ray节点/SSR节点|免费上网梯子每天更新
- 10月14日免费节点分享|22.5M/S,Clash节点/V2ray节点/Singbox节点/SSR节点|免费上网梯子每天更新
- 9月29日免费节点分享|22M/S,SSR节点/Singbox节点/V2ray节点/Clash节点|免费上网梯子每天更新
最新文章
- 跨越知识边界:浙大学子的全球学术网络探索指南
- 10月25日免费节点分享|18.1M/S,SSR节点/V2ray节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 10月24日免费节点分享|20.5M/S,V2ray节点/Clash节点/Singbox节点/Shadowrocket节点|免费上网梯子每天更新
- 刘大猫科学上网全攻略:解锁全球网络的终极指南
- 10月23日免费节点分享|22.2M/S,Shadowrocket节点/Clash节点/Singbox节点/V2ray节点|免费上网梯子每天更新
- 全面解析Quantumult安卓版:功能、安装与配置教程
- 双重防护,畅享无界:AdGuard联手V2RayNG,打造极致安全的上网体验
- 10月22日免费节点分享|18.8M/S,V2ray节点/SSR节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 掌握Clash白名单设置:精准控制代理流量的艺术
- 10月21日免费节点分享|22M/S,Clash节点/Singbox节点/V2ray节点/SSR节点|免费上网梯子每天更新
- 突破网络边界:技术科学上网的终极安全指南
- 10月20日免费节点分享|22.9M/S,SSR节点/V2ray节点/Clash节点/Singbox节点|免费上网梯子每天更新
- Shadowrocket 选购指南:从入门到精通,找到你的专属代理神器
- 10月19日免费节点分享|19.3M/S,Singbox节点/V2ray节点/Clash节点/Shadowrocket节点|免费上网梯子每天更新
- 深入解读:V2Ray为何比SSR更安全?一场网络隐私的全方位较量
- 10月18日免费节点分享|20.6M/S,V2ray节点/Clash节点/SSR节点/Singbox节点|免费上网梯子每天更新
- 深度指南:Shadowrocket从入门到精通——iOS用户的网络自由密钥
- 10月17日免费节点分享|18M/S,Clash节点/SSR节点/V2ray节点/Singbox节点|免费上网梯子每天更新
- 深入解析科学上网套:全方位使用指南与常见问题解答
- 10月16日免费节点分享|22M/S,Shadowrocket节点/V2ray节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 10月15日免费节点分享|21.2M/S,Clash节点/SSR节点/V2ray节点/Singbox节点|免费上网梯子每天更新
- 全局掌控:安卓设备上 Clash 全局模式完整设置指南与深度解析
- 解锁全球游戏体验:育碧平台科学上网全攻略与深度解析
- 10月14日免费节点分享|22.5M/S,Clash节点/V2ray节点/Singbox节点/SSR节点|免费上网梯子每天更新
- 华为Mate 10科学上网全攻略:突破限制,畅游全球网络
- 10月13日免费节点分享|22.1M/S,V2ray节点/Clash节点/Singbox节点/Shadowrocket节点|免费上网梯子每天更新
- 10月12日免费节点分享|22.7M/S,Shadowrocket节点/V2ray节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 量子ULT全方位指南:从下载配置到高阶玩法一网打尽
- 10月11日免费节点分享|18.6M/S,V2ray节点/Clash节点/SSR节点/Singbox节点|免费上网梯子每天更新
- 极路由V2ray插件完全指南:打造家庭网络的安全屏障
- 10月10日免费节点分享|18.3M/S,V2ray节点/Singbox节点/Clash节点/SSR节点|免费上网梯子每天更新
- 极速狂飙与正义追击:《警车 Clash》深度解析与高阶攻略
- 10月9日免费节点分享|22.3M/S,Singbox节点/Clash节点/Shadowrocket节点/V2ray节点|免费上网梯子每天更新
- 用hosts文件科学上网:一份从入门到实战的详细指南
- 10月8日免费节点分享|22.5M/S,V2ray节点/Singbox节点/Clash节点/Shadowrocket节点|免费上网梯子每天更新
- iOS设备上SSR科学上网全教程:从入门到精通
- 10月7日免费节点分享|23M/S,Singbox节点/Clash节点/Shadowrocket节点/V2ray节点|免费上网梯子每天更新
- 深度剖析V2Ray订阅机制:从零搭建高效、安全的科学上网环境
- 10月6日免费节点分享|19.2M/S,V2ray节点/Singbox节点/Shadowrocket节点/Clash节点|免费上网梯子每天更新
- 全面解析蚕蛹生态冲突及其多元价值
- 10月5日免费节点分享|19.9M/S,Singbox节点/Clash节点/V2ray节点/SSR节点|免费上网梯子每天更新
- 从零开始:手把手教你刷梅林固件实现安全科学上网
- 10月4日免费节点分享|20M/S,SSR节点/V2ray节点/Clash节点/Singbox节点|免费上网梯子每天更新
- 跨越边界,自由探索:一加科学上网全面指南与深度解析
- 10月3日免费节点分享|20.1M/S,SSR节点/Singbox节点/V2ray节点/Clash节点|免费上网梯子每天更新
- 10月2日免费节点分享|22.8M/S,Singbox节点/Shadowrocket节点/Clash节点/V2ray节点|免费上网梯子每天更新
- 斐讯K2路由器刷机全攻略:解锁科学上网新境界
- 解锁网络自由:B站d手机科学上网全攻略
- 10月1日免费节点分享|18M/S,Clash节点/V2ray节点/Singbox节点/SSR节点|免费上网梯子每天更新
- 洞悉网络脉络:一份关于Vmess节点测试的全景式实践手记
归档
- 2026-10 49
- 2026-09 58
- 2026-08 63
- 2026-07 61
- 2026-06 55
- 2026-05 56
- 2026-04 51
- 2026-03 60
- 2026-02 52
- 2026-01 56
- 2025-12 59
- 2025-11 55
- 2025-10 56
- 2025-09 55
- 2025-08 49
- 2025-07 31
- 2025-06 30
- 2025-05 31
- 2025-04 30
- 2025-03 388
- 2025-02 360
- 2025-01 403
- 2024-12 403
- 2024-11 390
- 2024-10 403
- 2024-09 388
- 2024-08 402
- 2024-07 427
- 2024-06 442
- 2024-05 181
- 2024-04 33
- 2024-03 31
- 2024-02 29
- 2024-01 51
- 2023-12 52
- 2023-11 32
- 2023-10 32
- 2023-09 3