{"id":3784,"date":"2022-06-26T21:08:22","date_gmt":"2022-06-26T13:08:22","guid":{"rendered":"\/?p=3784"},"modified":"2022-06-26T21:08:22","modified_gmt":"2022-06-26T13:08:22","slug":"8-flink%e7%9a%84cdc","status":"publish","type":"post","link":"http:\/\/xinblog.ltd\/?p=3784","title":{"rendered":"8.Flink\u7684CDC"},"content":{"rendered":"<p>Flink\u7684CDC<\/p>\n<p>\u5bf9\u4e8eFlink\u8fd9\u79cd\u6570\u636e\u5904\u7406\u4e2d\u95f4\u4ef6,\u6709\u4e00\u79cd\u9700\u6c42\u662f\u76d1\u6d4b\u5e76\u6355\u83b7\u6570\u636e\u5e93\u7684\u53d8\u5316,\u7136\u540e\u5c06\u8fd9\u4e9b\u53d8\u5316\u8bb0\u5f55\u4e0b\u6765,\u5199\u5165\u6d88\u606f\u4e2d\u95f4\u4ef6\u4f9b\u5176\u4ed6\u7684\u670d\u52a1\u8fdb\u884c\u8ba2\u9605\u548c\u6d88\u8d39,\u8fd9\u79cd\u64cd\u4f5c\u7684\u5168\u79f0\u5c31\u662fChange\u00a0Data Capture \u53d8\u66f4\u6570\u636e\u83b7\u53d6<\/p>\n<p>CDC\u7684\u79cd\u7c7b\u6309\u7167\u83b7\u53d6\u7684\u65b9\u5f0f\u5206\u4e3a\u4e24\u7c7b,\u5206\u522b\u4e3a\u67e5\u8be2 \u548c Binlog\u83b7\u53d6<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"602\" height=\"125\" class=\"wp-image-3785\" src=\"\/wp-content\/uploads\/2022\/06\/unnamed-file-48.png\" alt=\"\u56fe\u7247\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2022\/06\/unnamed-file-48.png 602w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2022\/06\/unnamed-file-48-300x62.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/p>\n<p>\u90a3\u4e48Flink\u63d0\u4f9b\u4e86 Flink-cdc-connectors\u7ec4\u4ef6,\u53ef\u4ee5\u76f4\u63a5\u4eceMySQL PostgreSQL \u7b49\u6570\u636e\u5e93\u76f4\u63a5\u83b7\u53d6\u5168\u91cf\u6570\u636e\u548c\u589e\u91cf\u53d8\u66f4\u6570\u636e\u7684source\u7ec4\u4ef6<\/p>\n<p><a href=\"https:\/\/github.com\/ververica\/flink-cdc-connectors\">https:\/\/github.com\/ververica\/flink-cdc-connectors<\/a><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"442\" height=\"130\" class=\"wp-image-3786\" src=\"\/wp-content\/uploads\/2022\/06\/unnamed-file-49.png\" alt=\"\u56fe\u7247\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2022\/06\/unnamed-file-49.png 442w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2022\/06\/unnamed-file-49-300x88.png 300w\" sizes=\"(max-width: 442px) 100vw, 442px\" \/><\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u7684\u64cd\u4f5c\u5c31\u662f\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93<\/p>\n<p>\u7136\u540e\u5728\u5bf9\u5e94\u7684mysql config\u4e2d\u6dfb\u52a0\u914d\u7f6e,\u589e\u52a0binlog\u7684\u540c\u6b65\u6570\u636e\u5e93<\/p>\n<table>\n<tbody>\n<tr>\n<td># binlog \u683c\u5f0f<\/p>\n<p>binlog_format=ROW<\/p>\n<p># \u6307\u5b9a\u5177\u4f53\u8981\u540c\u6b65\u7684\u6570\u636e\u5e93<\/p>\n<p>binlog_do_db=gmall_itdachang<\/p>\n<p>server_id=1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u800c\u5bf9\u4e8ejava\u9879\u76ee\u4e2d\u7684\u4f7f\u7528<\/p>\n<p>\u9996\u5148\u5bfc\u5165\u4e00\u4e2a\u4f9d\u8d56<\/p>\n<table>\n<tbody>\n<tr>\n<td>&lt;dependency&gt;<\/p>\n<p>&lt;groupId&gt;com.alibaba.ververica&lt;\/groupId&gt;<\/p>\n<p>&lt;artifactId&gt;flink-connector-mysql-cdc&lt;\/artifactId&gt;<\/p>\n<p>&lt;version&gt;1.2.0&lt;\/version&gt;<\/p>\n<p>&lt;\/dependency&gt;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7136\u540e\u7f16\u5199\u5bf9\u5e94\u7684\u4ee3\u7801<\/p>\n<p>\u9996\u5148\u662f\u51c6\u5907\u597d\u5bf9\u5e94\u7684\u73af\u5883<\/p>\n<p>StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();<\/p>\n<p>env.setParallelism(1);<\/p>\n<p>\u7136\u540e\u521b\u5efaMysql\u7684Source<\/p>\n<table>\n<tbody>\n<tr>\n<td>Properties props = new Properties();<\/p>\n<p>props.setProperty(&#8220;scan.startup.mode&#8221;,&#8221;initial&#8221;);<\/p>\n<p>SourceFunction&lt;String&gt; sourceFunction = MySQLSource.&lt;String&gt;builder()<\/p>\n<p>.hostname(&#8220;linux1&#8221;)<\/p>\n<p>.port(3306)<\/p>\n<p>.username(&#8220;root&#8221;)<\/p>\n<p>.password(&#8220;123123&#8221;)<\/p>\n<p>.databaseList(&#8220;test&#8221;)<\/p>\n<p>\/\/\/\u53ef\u9009\u914d\u7f6e\u9879,\u5982\u679c\u4e0d\u6307\u5b9a\u8be5\u53c2\u6570,\u5219\u4f1a\u8bfb\u53d6\u4e0a\u4e00\u4e2a\u914d\u7f6e\u4e2d\u6307\u5b9a\u7684\u6570\u636e\u5e93\u4e0b\u7684\u6240\u6709\u8868\u7684\u6570\u636e<\/p>\n<p>\/\/\u6ce8\u610f\uff1a\u6307\u5b9a\u7684\u65f6\u5019\u9700\u8981\u4f7f\u7528&#8221;db.table&#8221;\u7684\u65b9\u5f0f<\/p>\n<p>.tableList(&#8220;test.t_user&#8221;)<\/p>\n<p>.debeziumProperties(props)<\/p>\n<p>.deserializer(new StringDebeziumDeserializationSchema())<\/p>\n<p>.build();<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u65f6\u5019\u7684\u8f93\u51fa\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u683c\u5f0f\u7684<\/p>\n<p>\u5982\u679c\u5e0c\u671b\u8fdb\u884c\u5e8f\u5217\u5316\u7684\u683c\u5f0f\u53d8\u66f4,\u53ef\u4ee5\u8003\u8651\u81ea\u5df1\u5b9e\u73b0<\/p>\n<p>DebeziumDeserializationSchema\u63a5\u53e3<\/p>\n<p>\u8fd9\u5c31\u662fCDC\u7684\u57fa\u672c\u4f7f\u7528<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flink\u7684CDC \u5bf9\u4e8eFli [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"_links":{"self":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/3784"}],"collection":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3784"}],"version-history":[{"count":0,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/3784\/revisions"}],"wp:attachment":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3784"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}