当前位置:网站首页>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 .
边栏推荐
- 数据仓库工具superset安装(完全可用)
- Spark中的Structured Streaming
- 基于php心理健康服务系统获取(php毕业设计)
- 变量,流程控制与游标
- 项目不报错,正常运行,无法请求到服务
- JS macro task and micro task
- MySQL trigger
- Hit your face ins? Mars digital collection platform explores digital collection light social networking
- On how digital collections and entities can empower each other
- 2:为什么要读写分离
猜你喜欢

Books - social animals

DataX installation and use

Create a virtual environment using pycharm

Sales notice: on July 22, the "great heat" will be sold, and the [traditional national wind 24 solar terms] will be sold in summer.

How digital library realizes Web3.0 social networking

南京邮电大学CTF题目writeup (一) 含题目地址
![Notice of attack: [bean Bingbing] send, sell, cash, draw, prize, etc](/img/53/d6db223712c4fe0cdcab313ec5dea8.jpg)
Notice of attack: [bean Bingbing] send, sell, cash, draw, prize, etc

Books - mob

【六】redis缓存策略

Xshell suddenly failed to connect to the virtual machine
随机推荐
MySQL trigger
【七】redis缓存与数据库数据一致性
【六】redis缓存策略
XShell突然间无法连接虚拟机
【三】redis特点功能
Books - mob
Books - Templeton teaches you reverse
数字藏品成文旅产业新热点
单行函数,聚合函数课后练习
Linux(centOs7) 下安装redis
内网信息收集总结
【五】redis主从同步与Redis Sentinel(哨兵)
On July 7, the national wind 24 solar terms "Xiaoshu" came!! Attachment.. cooperation.. completion.. advance.. report
regular expression
mysql分页出现问题
(php毕业设计)基于php水果销售商店管理系统获取
Progressive enhancement and graceful degradation
Distinguish between real-time data, offline data, streaming data and batch data
3:Mysql 主从复制搭建
xml解析实体工具类