Flink CDC -Sqlserver to Sqlserver java 模版编写

1.基本环境

     <flink.version>1.17.0</flink.version>

2. 类文件

package com.flink.tablesql;import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;import java.io.File;
import java.util.List;public class Main2 {public static void main(String[] args) throws Exception {StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();env.setParallelism(1);StreamTableEnvironment tabEnv = StreamTableEnvironment.create(env);String path = "E:\\test\\flinktestsql\\orders.sql";
//        String path = "/data/flink/flinksql/orders.sql";List<String> list = FileUtils.readLines(new File(path),"UTF-8");StringBuilder stringBuilder = new StringBuilder("");String sql = "";for(String var : list){if(StringUtils.isNotBlank(var)){stringBuilder.append(var);if(var.contains("$")){sql = stringBuilder.toString().replace("$","");System.out.println(sql);System.out.println("end-----");tabEnv.executeSql(sql);stringBuilder = new StringBuilder("");}else{stringBuilder.append("\n");}}}}
}

3.pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>flinktestsql</artifactId><version>1.0-SNAPSHOT</version><!--    &lt;!&ndash; 指定仓库位置,依次为aliyun、apache和cloudera仓库 &ndash;&gt;--><repositories><repository><id>aliyun</id><url>https://maven.aliyun.com/repository/public</url></repository><repository><id>apache</id><url>https://maven.aliyun.com/repository/apache-snapshots</url></repository><repository><id>cloudera</id><url>https://maven.aliyun.com/repository/gradle-plugin</url></repository><repository><id>central</id><url>https://maven.aliyun.com/repository/central</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><!--版本--><properties><encoding>UTF-8</encoding><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><flink.version>1.17.0</flink.version><slf4j.version>2.0.5</slf4j.version><scala.binary.version>2.11</scala.binary.version><scala.version>2.11.12</scala.version></properties><dependencies><!-- Flink相关依赖 --><dependency><groupId>org.apache.flink</groupId><artifactId>flink-java</artifactId><version>${flink.version}</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-streaming-java</artifactId><version>${flink.version}</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-clients</artifactId><version>${flink.version}</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-connector-files</artifactId><version>${flink.version}</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-table-api-java</artifactId><version>1.17.0</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-table-api-java-bridge</artifactId><version>${flink.version}</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-table-planner-loader</artifactId><version>${flink.version}</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-table-runtime</artifactId><version>${flink.version}</version></dependency><dependency><groupId>com.microsoft.sqlserver</groupId><artifactId>mssql-jdbc</artifactId><version>11.2.1.jre8</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-json</artifactId><version>1.11.0</version></dependency><dependency><groupId>com.ververica</groupId><artifactId>flink-connector-sqlserver-cdc</artifactId><version>2.4.2</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-connector-jdbc</artifactId><version>3.1.1-1.17</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-table-test-utils</artifactId><version>1.17.1</version><scope>test</scope></dependency><!-- 日志管理相关依赖 --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>${slf4j.version}</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>${slf4j.version}</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-to-slf4j</artifactId><version>2.19.0</version></dependency></dependencies></project>

4.后续只需要修改增加 .sql文件即可

       String path = "E:\\test\\flinktestsql\\orders.sql";

        // String path = "/data/flink/flinksql/orders.sql";

5.以上在本地运行未通过报错,在flink web 界面配置运行可以。我看网上可能是需要修改本地jdk配置,没有修改。

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target”。 ClientConnectionId:d5fb789f-e4e9-416f-b47c-57dc09429ebfat com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:3806)at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1906)

6.flink web 端配置如下:只上传jar不行,还需要配置配置类,才可以

7.以上遇到很多问题,总算解决了,

如增加:

<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/223394.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【从删库到跑路 | MySQL总结篇】表的增删查改(进阶上)

个人主页&#xff1a;兜里有颗棉花糖 欢迎 点赞&#x1f44d; 收藏✨ 留言✉ 加关注&#x1f493;本文由 兜里有颗棉花糖 原创 收录于专栏【MySQL学习专栏】&#x1f388; 本专栏旨在分享学习MySQL的一点学习心得&#xff0c;欢迎大家在评论区讨论&#x1f48c; 目录 一、数据…

【C语言】【选择排序及其优化】

选择排序是指&#xff1a;第一次从待排序的数据元素中选出最小&#xff08;或最大&#xff09;的一个元素&#xff0c;存放在序列的起始位置&#xff0c;然后再从剩余的未排序元素中寻找到最小&#xff08;大&#xff09;元素&#xff0c;然后放到已排序的序列的末尾&#xff0…

论文阅读:“Appearance Capture and Modeling of Human Teeth”

文章目录 AbstractIntroductionMethod OverviewTeeth Appearance ModelEnamelDentinGingiva and oral cavity Data AcquisitionImage captureGeometry capture ResultsReferences Abstract 如果要为电影&#xff0c;游戏或其他类型的项目创建在虚拟环境中显示的人类角色&#…

Python---引用变量与可变、非可变类型

引用变量 在大多数编程语言中&#xff0c;值的传递通常可以分为两种形式“ 值 传递 与 引用 传递”&#xff0c;但是在Python中变量的传递基本上都是引用传递。 变量在内存底层的存储形式 a 10 第一步&#xff1a;首先在计算机内存中创建一个数值10&#xff08;占用一块…

计算机组成原理——小啃一下

CPU和主存储器结构 CPU&#xff1a; 运算器 ACC&#xff08;累加器&#xff09;ALU&#xff08;算数逻辑单元&#xff09;MQ&#xff08;乘商寄存器&#xff09;X&#xff08;操作数寄存器&#xff09; 控制器 CU&#xff08;控制单元&#xff09;IR&#xff08;指令寄存器&a…

Linux基础项目开发1:量产工具——程序框架(一)

前言&#xff1a; 前面已经将Linux应用开发基础知识学习完了&#xff0c;现在让我们来做个小项目练练手&#xff0c;对之前的一些知识点进行一个更加具体详细的认识与了解&#xff0c;我们要进行的项目名称为&#xff1a;电子产品量产测试与烧写工具&#xff0c;这是一套软件&a…

【单调栈】最大宽度坡

public int maxWidthRamp(int[] nums) {/* 此方法思路正确&#xff0c;但超时int n nums.length;Deque<Integer> stack;int max 0;for (int i 0; i < n; i) {stack new LinkedList<>();stack.push(nums[i]);int j i 1;while (j < n) {stack.push(nums…

已知两个链表L1和L2分别表示两个集合,其中元素递增排列。请设计一个算法,用于求出L1与L2的交集,并存放在L1链表中

已知两个链表L1和L2分别表示两个集合&#xff0c;其中元素递增排列。请设计一个算法&#xff0c;用于求出L1与L2的交集&#xff0c;并存放在L1链表中。 代码思路&#xff1a; 我们创建一个辅助链表L3&#xff0c;用于存储L1和L2链表的交集&#xff0c;用s遍历L3各个元素 用p和…

文件夹重命名:克服语言障碍,批量将中文文件夹名翻译成英文

随着全球化的不断深入&#xff0c;英语成为了世界上最广泛使用的语言。在日常生活和工作中&#xff0c;可能经常要将中文文件夹名翻译成英文&#xff0c;以便交流或满足特定需求。手动翻译文件夹名不仅耗时&#xff0c;还容易出错。那有什么方法可以快速、准确地批量将中文文件…

【Qt】判断QList链表内是否有重复数据

QList<int> listInt;listInt.push_back(1);listInt.push_back(1);listInt.push_back(2);listInt.push_back(3);qDebug().noquote() << listInt.toSet().toList();

【前端开发】Remix与Next.js

很容易&#xff0c;我们被问到的最大问题是&#xff1a; Remix与Next.js有何不同&#xff1f; 看来我们必须回答这个问题&#xff01;我们想直接而不带戏剧性地解决这个问题。如果你是Remix的粉丝&#xff0c;并且想开始在推特上对这篇文章做出沾沾自喜的反应&#xff0c;我们恳…

2019年8月15日 Go生态洞察:Go贡献者峰会2019回顾

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…