Git Product home page Git Product logo

flinkproj's Introduction

FlinkProj 案例开发

应用场景:

  • 数据清洗【实时ETL】
  • 数据报表

1、数据清洗【实时ETL】

在这里插入图片描述

1.1、需求分析

针对算法产生的日志数据进行清洗拆分

  1. 算法产生的日志数据是嵌套大JSON格式(json嵌套json),需要拆分打平
  2. 针对算法中的国家字段进行大区转换
  3. 最后把不同类型的日志数据分别进行存储

1.2、数据清理 DataClean 结构

在这里插入图片描述

1.3、实践运行

1.3.1、Redis

启动redis:

  1. 先从一个终端启动redis服务
./redis-server

在这里插入图片描述   2. 先从一个终端启动redis客户端,并插入数据

./redis-cli
127.0.0.1:6379> hset areas   AREA_US   US
(integer) 1
127.0.0.1:6379> hset areas   AREA_CT   TW,HK
(integer) 1
127.0.0.1:6379> hset areas   AREA_AR   PK,SA,KW
(integer) 1
127.0.0.1:6379> hset areas   AREA_IN   IN
(integer) 1
127.0.0.1:6379>

1.3.2、Kafka

启动kafka:

./kafka-server-start.sh -daemon ../config/server.properties

kafka创建topc:

./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 5 --topic allData

监控kafka topic:

./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic allDataClean

1.3.3、启动程序

先启动 DataClean 程序,再启动生产者程序,kafka生产者产生数据如下:

最后终端观察处理输出的数据: 在这里插入图片描述 只有部分数据正确处理输出的原因是:代码中没有设置并行度,默认是按机器CPU核数跑的,这里需要通过 broadcast() 进行广播

1.4、Flink yarn集群启动

向yarn提交任务:

./bin/flink run -m yarn-cluster -yn 2 -yjm 1024 -ytm 1024 -c henry.flink.DataClean /root/flinkCode/DataClean-1.0-SNAPSHOT-jar-with-dependencies.jar

通过 yarn UI 查看任务,并进入Flink job: 在这里插入图片描述

启动kafka生产者: 在这里插入图片描述 监控topic消费情况:

./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic allDataClean

最终终端输出结果, 同IDEA中运行结果:

flinkproj's People

Contributors

henrybao91 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.