首页 技术 正文
技术 2022年11月15日
0 收藏 867 点赞 4,255 浏览 1262 个字

以前的数据分析项目(版本1.4.2),对从Kafka读取的原始数据流,调用split接口实现分流.

新项目决定使用Flink 1.7.2,使用split接口进行分流的时候,发现接口被标记为depracted(后续可能会被移除).

搜索相关文档,发现新版本Flink中推荐使用带外数据进行分流.

预先建立OutputTag实例(LogEntity是从kafka读取的日志实例类).

private static final OutputTag<LogEntity> APP_LOG_TAG = new OutputTag<>("appLog", TypeInformation.of(LogEntity.class));
private static final OutputTag<LogEntity> ANALYZE_METRIC_TAG = new OutputTag<>("analyzeMetricLog", TypeInformation.of(LogEntity.class));

kafka读取的原始数据,通过process接口,打上相应标记.

    private static SingleOutputStreamOperator<LogEntity> sideOutStream(DataStream<LogEntity> rawLogStream) {
return rawLogStream
.process(new ProcessFunction<LogEntity, LogEntity>() {
@Override
public void processElement(LogEntity entity, Context ctx, Collector<LogEntity> out) throws Exception {
// 根据日志等级,给对象打上不同的标记
if (entity.getLevel().equals(ANALYZE_LOG_LEVEL)) {
ctx.output(ANALYZE_METRIC_TAG, entity);
} else {
ctx.output(APP_LOG_TAG, entity);
}
}
})
.name("RawLogEntitySplitStream");
} // 调用函数,对原始数据流中的对象进行标记
SingleOutputStreamOperator<LogEntity> sideOutLogStream = sideOutStream(rawLogStream);
// 根据标记,获取不同的数据流,以便后续进行进一步分析
DataStream<LogEntity> appLogStream = sideOutLogStream.getSideOutput(APP_LOG_TAG);
DataStream<LogEntity> rawAnalyzeMetricLogStream = sideOutLogStream.getSideOutput(ANALYZE_METRIC_TAG);

通过以上步骤,就实现了数据流的切分.

PS:

如果您觉得我的文章对您有帮助,请关注我的微信公众号,谢谢!

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,135
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,299