先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新大数据全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip204888 (备注大数据)
正文
" 'topic' = 'mysql_cdc',\n" + --写到kafka的主题,必填
" 'properties.bootstrap.servers' = 'hadoop102:9092',\n" + --kafka服务器名
" 'properties.group.id' = 'testGroup',\n" +
" 'scan.startup.mode' = 'earliest-offset',\n" +
" 'format' = 'debezium-json'\n" + --日志json格式,必填
")");
tEnv.executeSql(“insert into kfk_cdc select * from Person”);
最后将目标表中的数据写到kafka的表中,因为flinksql连接kafka底层会将kafka表中数据自动写到kafka中
![](https://img-blog.csdnimg.cn/direct/a13d8a7fce3845ccb441c58c7fd6b1b2.png)
可能这样你们看不清,我把json数据美化一下
![](https://img-blog.csdnimg.cn/direct/27d5f431d7ad4511b9e15e729c8a9b32.png)
### 第二种用FlinkApi实现
第二步,第三步和FlinkSql一样
第四步从官网上复制: [Overview | Apache Flink CDC]( )
![](https://img-blog.csdnimg.cn/direct/7f76624ab1744a9e90e3ca77dc03358b.png)
//免密配置
Properties properties = new Properties();
properties.put(“useSSL”,“false”);
MySqlSource mySqlSource = MySqlSource.builder()
.hostname(“hadoop102”) --必填 主机名
.port(3306) --必填 端口号
.databaseList(“zg3”) // set captured database --必填 数据库
.tableList(“zg3.Person”)// set captured table --必填 数据表
.username(“root”) --必填 用户名
.password(“123456”) --必填 密码
.deserializer(new JsonDebeziumDeserializationSchema()) --反序列化器
.jdbcProperties(properties) --jdbc配置,用来写免密配置
.build();
#### 第五步:获取上一步源数据
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
// enable checkpoint
env.enableCheckpointing(3000);
env
.fromSource(mySqlSource, WatermarkStrategy.noWatermarks(), "MySQL Source")
// set 4 parallel source tasks
.setParallelism(1)
.print(); // use parallelism 1 for sink to keep message ordering
env.execute("Print MySQL Snapshot + Binlog");
![](https://img-blog.csdnimg.cn/direct/c67d88aa2f46461790b39bf839b28e9c.png)
#### 第六步:将数据转化为json格式
第一种:StringDebeziumDeserializationSchema()
>
> SourceRecord{sourcePartition={server=mysql\_binlog\_source}, sourceOffset={transaction\_id=null, ts\_sec=1712331615, file=, pos=0}} ConnectRecord{topic='mysql\_binlog\_source.zg3.Person', kafkaPartition=null, key=Struct{id=2}, keySchema=Schema{mysql\_binlog\_source.zg3.Person.Key:STRUCT}, value=Struct{after=Struct{id=2,name=中国,age=22,sex=男},source=Struct{version=1.9.7.Final,connector=mysql,name=mysql\_binlog\_source,ts\_ms=0,db=zg3,table=Person,server\_id=0,file=,pos=0,row=0},op=r,ts\_ms=1712331615095}, valueSchema=Schema{mysql\_binlog\_source.zg3.Person.Envelope:STRUCT}, timestamp=null, headers=ConnectHeaders(headers=)}
>
>
>
>
MySqlSource mySqlSource = MySqlSource.builder()
.hostname(“hadoop102”)
.port(3306)
.databaseList(“zg3”) // set captured database
.tableList(“zg3.Person”)// set captured table
.username(“root”)
.password(“123456”)
.deserializer(new StringDebeziumDeserializationSchema()) // converts SourceRecord to JSON String
.jdbcProperties(properties)
.build();
第二种: JsonDebeziumDeserializationSchema()
>
> {"before":null,"after":{"id":2,"name":"中国","age":22,"sex":"男"},"source":{"version":"1.9.7.Final","connector":"mysql","name":"mysql\_binlog\_source",
>
>
> "ts\_ms":0,"snapshot":"false","db":"zg3","sequence":null,"table":"Person",
>
>
> "server\_id":0,"gtid":null,"file":"","pos":0,"row":0,"thread":null,"query":null},
>
>
> "op":"r","ts\_ms":1712331713335,"transaction":null}
>
>
>
MySqlSource<String> mySqlSource = MySqlSource.<String>builder()
.hostname("hadoop102")
.port(3306)
.databaseList("zg3") // set captured database
.tableList("zg3.Person")// set captured table
.username("root")
.password("123456")
.deserializer(new JsonDebeziumDeserializationSchema()) // converts SourceRecord to JSON String
.jdbcProperties(properties)
.build();
第二种更加的符合我们日常的json格式
但我们不想其余东西,只想要after、before、database、table 、operation
这时候我们就需要自定义了
public static class PersonDeserialization implements DebeziumDeserializationSchema <String>{
@Override
public void deserialize(SourceRecord sourceRecord, Collector collector) throws Exception {
//获取database和table
String topic = sourceRecord.topic();
String[] split = topic.split("\\.");
String database = split[1];
String table = split[2];
JSONObject data = new JSONObject();
//获取value值
//获取before值
Struct value = (Struct) sourceRecord.value();
Struct before = value.getStruct("before");
JSONObject beforeData = new JSONObject();
if(before!=null){
for (Field field : before.schema().fields()) {
Object o = before.get(field);
beforeData.put(field.name(),o);
}
}else{
before=null;
}
//获取after值
Struct after = value.getStruct("after");
JSONObject afterData = new JSONObject();
for (Field field : after.schema().fields()) {
Object o = after.get(field);
afterData.put(field.name(),o);
}
data.put("before",beforeData);
data.put("after",afterData);
//获取操作类型
Envelope.Operation operation = Envelope.operationFor(sourceRecord);
//装配数据
JSONObject object = new JSONObject();
object.put("database",database);
object.put("table",table);
object.put("before",beforeData);
object.put("after",afterData);
collector.collect(object.toString());
}
@Override
public TypeInformation getProducedType() {
return BasicTypeInfo.STRING_TYPE_INFO;//这里一般就是写String类型了
}
}
>
>
>
> ```
> public static class PersonDeserialization implements DebeziumDeserializationSchema <String>{
>
> @Override
> public void deserialize(SourceRecord sourceRecord, Collector collector) throws Exception {
>
> //获取database和table
> String topic = sourceRecord.topic();
> String[] split = topic.split("\\.");
> String database = split[1];
> String table = split[2];
>
> JSONObject data = new JSONObject();
>
> //获取value值
> Struct value = (Struct) sourceRecord.value();
> Struct before = value.getStruct("before");
> JSONObject beforeData = new JSONObject();
> if(before!=null){
> for (Field field : before.schema().fields()) {
> Object o = before.get(field);
> beforeData.put(field.name(),o);
> }
> }else{
> before=null;
> }
>
>
> Struct after = value.getStruct("after");
> JSONObject afterData = new JSONObject();
> for (Field field : after.schema().fields()) {
> Object o = after.get(field);
> afterData.put(field.name(),o);
> }
>
> data.put("before",beforeData);
> data.put("after",afterData);
>
> //获取操作类型
> Envelope.Operation operation = Envelope.operationFor(sourceRecord);
>
> //装配数据
> JSONObject object = new JSONObject();
> object.put("database",database);
> object.put("table",table);
> object.put("before",beforeData);
> object.put("after",afterData);
>
>
> collector.collect(object.toString());
> }
>
> @Override
> public TypeInformation getProducedType() {
> return BasicTypeInfo.STRING_TYPE_INFO;
> }
> }
> ```
>
>
上面可以写成工具类,直接使用
![](https://img-blog.csdnimg.cn/direct/a7bc6b4553024bd38a98a331e5f313f3.png)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)**
![img](https://img-blog.csdnimg.cn/img_convert/f3b357b02981148245c0330ad41a15fb.png)
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
nimg.cn/direct/a7bc6b4553024bd38a98a331e5f313f3.png)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注大数据)**
[外链图片转存中...(img-0ENWVstv-1713284192511)]
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**