当前位置:网站首页>Flink CDC (MySQL as an example)
Flink CDC (MySQL as an example)
2022-07-28 06:03:00 【King_ Kwin】
background
There are often some large tables of tens of millions or even billions in business , At this time, it may be considered to divide the database and table (Sharding-JDBC、MyCat And so on ), Also often synchronize data entry ES in ; In the business scenario of synchronizing data ,Flink CDC It's a good solution .
programme
Such as mysql、postgresql、sqlserver etc. ,flink cdc By reading the binlog journal ( Be careful : Please open first. binlog journal ), Data synchronization , Good real-time performance .
The analysis and consumption of data are encapsulated twice , Users only need to add simple configuration , Realization FlinkConsumerListener Interface , Just focus on writing business code .
Code
show coding
test demo
Create a springboot project
Depend on the introduction of ( Introduce the dependencies after the packaging of the above projects )
<dependency>
<groupId>com.kwin</groupId>
<artifactId>flink</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>The configuration file
flink:
pipeline-name: flinkCDCTest
mysqlDataSource:
- port: 3306
hostname: 127.0.0.1
databaseList:
- flinktest
tableList:
- flinktest.student
username: root
password: 123456Above , in the light of flinktest Database student table binlog monitor .
flinktest.student The consumer
student Entity
import lombok.Data;
/**
* @author kwin
* @Date 2022/7/25 18:27
**/
@Data
public class Student {
private Long id;
private String name;
private Integer age;
private Integer maxInx;
}consumer
import com.kwin.demo.server.module.flink.test.entity.Student;
import com.kwin.flink.sink.FlinkConsumerListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author kwin
* @Date 2022/7/25 18:29
**/
@Slf4j
@Component
public class StudentConsumerListener implements FlinkConsumerListener<Student> {
@Override
public String getDBName() {
return "flinktest";
}
@Override
public String getTable() {
return "student";
}
@Override
public void insert(Student data) {
System.out.println("insert: " + data);
}
@Override
public void update(Student srcData, Student destData) {
System.out.println("update: \nsrc:" + srcData + "\ndest:" + destData);
}
@Override
public void delete(Student data) {
System.out.println("delete:"+data);
}
}
Start project
flinktest.student When modifying data :

flinktest.student When inserting data :

flinktest.student When deleting data :

Above , Users only need to implement FlinkConsumerListener Interface , You can perform consumption and business logic operations on the data of the specified table .
边栏推荐
- Beginner mobile terminal
- 数字藏品以虚强实,赋能实体经济发展
- 登录时密码错误次数过多,对该用户进行封禁,
- 变量,流程控制与游标
- (php毕业设计)基于php校园网络报修管理系统获取
- raise RuntimeError(‘DataLoader worker (pid(s) {}) exited unexpectedly‘.format(pids_str))RuntimeErro
- Mars数*字*藏*品*平*台守卫者计划细节公布
- MySQL select statement query; Operator after class practice
- Single line function, aggregate function after class exercise
- Hit your face ins? Mars digital collection platform explores digital collection light social networking
猜你喜欢

Wechat official account - authorized login

接口防重复提交

7月7日国风廿四节气《小暑》来袭!!附..合..成..预..告..

JS macro task and micro task

How digital library realizes Web3.0 social networking

1:开启慢查询日志 与 找到慢SQL

Related concepts and operations of DOM model

南京邮电大学CTF题目writeup (一) 含题目地址
Installation and use of sqoop

CVE_2017_11882漏洞复现(Metasploit开启NT远程桌面添加账户)
随机推荐
Invalid packaging for parent POM x, must be “pom“ but is “jar“ @
连续登陆问题
[uni app] the use of scroll into view in uni app
raise RuntimeError(‘DataLoader worker (pid(s) {}) exited unexpectedly‘.format(pids_str))RuntimeErro
Flink CDC (Mysql为例)
MYSQL的select语句查询;运算符课后练习
数据仓库工具superset安装(完全可用)
【五】redis主从同步与Redis Sentinel(哨兵)
(php毕业设计)基于php在线旅游网站管理系统获取
出游不易,看景区用数字藏品刷存在感
The combination of cultural tourism and digital collections has a significant effect, but how to support users' continuous purchasing power
ModuleNotFoundError: No module named ‘pip‘
Books - Templeton teaches you reverse
Prime_Series靶场从探测到提权
第七章 单行函数
Tiktok - VIDEO steps
mysql分页出现问题
(PHP graduation project) obtained based on PHP student homework submission management system
反弹shell的N种姿势
发售预告:7月22日“大暑”发售,【传统国风廿四节气】夏季发售完毕。