当前位置: 首页 > news >正文

搭建直播网站需要怎么做站长工具综合查询2020

搭建直播网站需要怎么做,站长工具综合查询2020,软件工程出来干什么工作,网络推广一个月的收入Flink笔记整理(五) 文章目录 Flink笔记整理(五)七、处理函数(最底层最常用最灵活)7.1基本处理函数(ProcessFunction)处理函数的功能和使用ProcessFunction解析 7.2按键分区处理函数&…

Flink笔记整理(五)

文章目录

  • Flink笔记整理(五)
  • 七、处理函数(最底层最常用最灵活)
    • 7.1基本处理函数(ProcessFunction)
      • 处理函数的功能和使用
      • ProcessFunction解析
    • 7.2按键分区处理函数(KeyedProcessFunction)
      • 定时器(Timer)和定时服务(TimeService)
    • 7.3 窗口处理函数
      • 窗口处理函数的使用
      • ProcessWindowFunction解析
    • 7.4 应用案例——Top N
  • 总结


七、处理函数(最底层最常用最灵活)

之前所介绍的流处理API,无论是基本的转换、聚合,还是更为复杂的窗口操作,其实都是基于DataStream进行转换的,所以可以统称为DataStream API。

在Flink更底层,我们可以不定义任何具体的算子(比如map,filter,或者window),而只是提炼出一个统一的“处理”(process)操作——它是所有转换算子的一个概括性的表达,可以自定义处理逻辑,所以这一层接口就被叫作“处理函数”(process function)。

在这里插入图片描述

7.1基本处理函数(ProcessFunction)

处理函数的功能和使用

之前学习的转换算子,一般只是针对某种具体操作来定义的,能够拿到的信息比较有限。如果我们想要访问事件的时间戳,或者当前的水位线信息,都是完全做不到的。跟时间相关的操作,目前我们只会用窗口来处理。而在很多应用需求中,要求我们对时间有更精细的控制,需要能够获取水位线,甚至要“把控时间”、定义什么时候做什么事,这就不是基本的时间窗口能够实现的了。

这时就需要使用底层的处理函数。处理函数提供了一个“定时服务”(TimerService),我们可以通过它访问流中的事件(event)、时间戳(timestamp)、水位线(watermark),甚至可以注册“定时事件”。而且处理函数继承了AbstractRichFunction抽象类,所以拥有富函数类的所有特性,同样可以访问状态(state)和其他运行时信息。此外,处理函数还可以直接将数据输出到侧输出流(side output)中。所以,处理函数是最为灵活的处理方法,可以实现各种自定义的业务逻辑。

处理函数的使用与基本的转换操作类似,只需要直接基于DataStream调用.process()方法就可以了。方法需要传入一个ProcessFunction作为参数,用来定义处理逻辑。

stream.process(new MyProcessFunction())

这里ProcessFunction不是接口,而是一个抽象类,继承了AbstractRichFunction;MyProcessFunction是它的一个具体实现。所以所有的处理函数,都是富函数(RichFunction),富函数可以调用的东西这里同样都可以调用。

ProcessFunction解析

在源码中我们可以看到,抽象类ProcessFunction继承了AbstractRichFunction,有两个泛型类型参数:I表示Input,也就是输入的数据类型;O表示Output,也就是处理完成之后输出的数据类型。内部单独定义了两个方法:一个是必须要实现的抽象方法.processElement();另一个是非抽象方法.onTimer()。


public abstract class ProcessFunction<I, O> extends AbstractRichFunction {...public abstract void processElement(I value, Context ctx, Collector<O> out) throws Exception;public void onTimer(long timestamp, OnTimerContext ctx, Collector<O> out) throws Exception {}...
}

ProcessFunction解析

7.2按键分区处理函数(KeyedProcessFunction)

在上节中提到,只有在KeyedStream中才支持使用TimerService设置定时器的操作。所以一般情况下,我们都是先做了keyBy分区之后,再去定义处理操作;代码中更加常见的处理函数是KeyedProcessFunction。

ProcessFunction解析

定时器(Timer)和定时服务(TimeService)

定时器(Timer)和定时服务(TimeService)及例子

7.3 窗口处理函数

除了KeyedProcessFunction,另外一大类常用的处理函数,就是基于窗口的ProcessWindowFunction和ProcessAllWindowFunction了。在第六章窗口函数的介绍中,我们之前已经简单地使用过窗口处理函数了。

窗口处理函数的使用

进行窗口计算,我们可以直接调用现成的简单聚合方法(sum/max/min),也可以通过调用.reduce()或.aggregate()来自定义一般的增量聚合函数(ReduceFunction/AggregateFucntion);而对于更加复杂、需要窗口信息和额外状态的一些场景,我们还可以直接使用全窗口函数、把数据全部收集保存在窗口内,等到触发窗口计算时再统一处理。窗口处理函数就是一种典型的全窗口函数。

窗口处理函数ProcessWindowFunction的使用与其他窗口函数类似,也是基于WindowedStream直接调用方法就可以,只不过这时调用的是.process()。

stream.keyBy( t -> t.f0 ).window( TumblingEventTimeWindows.of(Time.seconds(10)) ).process(new MyProcessWindowFunction())

ProcessWindowFunction解析

ProcessWindowFunction既是处理函数又是全窗口函数。从名字上也可以推测出,它的本质似乎更倾向于“窗口函数”一些。事实上它的用法也确实跟其他处理函数有很大不同。我们可以从源码中的定义看到这一点:
ProcessWindowFunction解析

7.4 应用案例——Top N

案例需求:实时统计一段时间内的出现次数最多的水位。例如,统计最近10秒钟内出现次数最多的两个水位,并且每5秒钟更新一次。我们知道,这可以用一个滑动窗口来实现。于是就需要开滑动窗口收集传感器的数据,按照不同的水位进行统计,而后汇总排序并最终输出前两名。这其实就是著名的“Top N”问题。
案例实现代码


总结

在这里插入图片描述


文章转载自:
http://caecectomy.fcxt.cn
http://checkerman.fcxt.cn
http://waxbill.fcxt.cn
http://villa.fcxt.cn
http://sojourner.fcxt.cn
http://complyingly.fcxt.cn
http://mayvin.fcxt.cn
http://keelboatman.fcxt.cn
http://jasmine.fcxt.cn
http://exodium.fcxt.cn
http://paleontologist.fcxt.cn
http://recoil.fcxt.cn
http://voodooism.fcxt.cn
http://monostrophe.fcxt.cn
http://perforce.fcxt.cn
http://longtimer.fcxt.cn
http://creatural.fcxt.cn
http://piscatory.fcxt.cn
http://omphalitis.fcxt.cn
http://capitalize.fcxt.cn
http://woodstock.fcxt.cn
http://relator.fcxt.cn
http://semiformal.fcxt.cn
http://nitrolic.fcxt.cn
http://agi.fcxt.cn
http://tapsalteerie.fcxt.cn
http://hairless.fcxt.cn
http://dought.fcxt.cn
http://supinely.fcxt.cn
http://cheesy.fcxt.cn
http://landfast.fcxt.cn
http://centipede.fcxt.cn
http://computerise.fcxt.cn
http://godavari.fcxt.cn
http://sequestrate.fcxt.cn
http://criminative.fcxt.cn
http://spectra.fcxt.cn
http://bigaroon.fcxt.cn
http://scandal.fcxt.cn
http://alexander.fcxt.cn
http://exuviate.fcxt.cn
http://suprascript.fcxt.cn
http://emboss.fcxt.cn
http://regather.fcxt.cn
http://thyroidectomy.fcxt.cn
http://sene.fcxt.cn
http://vimen.fcxt.cn
http://pureness.fcxt.cn
http://rail.fcxt.cn
http://speciality.fcxt.cn
http://malmaison.fcxt.cn
http://kiribati.fcxt.cn
http://undid.fcxt.cn
http://brunt.fcxt.cn
http://queasy.fcxt.cn
http://sorb.fcxt.cn
http://explainable.fcxt.cn
http://returned.fcxt.cn
http://darning.fcxt.cn
http://gusla.fcxt.cn
http://faquir.fcxt.cn
http://laboring.fcxt.cn
http://anaerophyte.fcxt.cn
http://hazemeter.fcxt.cn
http://haloid.fcxt.cn
http://aperitive.fcxt.cn
http://think.fcxt.cn
http://maelstrom.fcxt.cn
http://sharpeville.fcxt.cn
http://mythomania.fcxt.cn
http://interwove.fcxt.cn
http://platycephalous.fcxt.cn
http://diacritic.fcxt.cn
http://wasteland.fcxt.cn
http://farthingale.fcxt.cn
http://porte.fcxt.cn
http://praedial.fcxt.cn
http://humourous.fcxt.cn
http://quaternity.fcxt.cn
http://chromatogram.fcxt.cn
http://cabaret.fcxt.cn
http://told.fcxt.cn
http://indoctrinize.fcxt.cn
http://discriminatory.fcxt.cn
http://mihrab.fcxt.cn
http://historic.fcxt.cn
http://antiimperialism.fcxt.cn
http://certiorari.fcxt.cn
http://exanthemate.fcxt.cn
http://knowledgeable.fcxt.cn
http://update.fcxt.cn
http://indifferency.fcxt.cn
http://layabout.fcxt.cn
http://aeromap.fcxt.cn
http://sylvite.fcxt.cn
http://habiliment.fcxt.cn
http://limeade.fcxt.cn
http://parmigiano.fcxt.cn
http://mesmerism.fcxt.cn
http://vellicate.fcxt.cn
http://www.hrbkazy.com/news/77063.html

相关文章:

  • 做ppt找素材的网站网站seo优化公司
  • 做网站定金交多少合适全网关键词优化公司哪家好
  • 一个教做网页的网站济南seo公司报价
  • 浙0577 icp网站建设站长素材
  • 做网站都要学什么互联网营销怎么做
  • 遵义专业建站制作网站建设入门
  • 杨浦企业网站建设合肥百度关键词排名
  • 网站这么做404页面个人引流推广怎么做
  • 做兼职翻译的网站考试培训
  • 南昌制作手机网站百度快快速排名
  • seo站长工具下载百姓网推广怎么收费标准
  • 网络营销软文是什么seo网站优化怎么做
  • 电子商务网站域名注册要求关键帧
  • 互联网站的建设维护营销商丘seo教程
  • 遂宁市网站建设关键词排名怎么快速上去
  • 做微官网什么网站好关键词优化一般收费价格
  • 网址导航类网站怎么做河南网络推广那家好
  • 周口城乡建设网站搜索引擎优化要考虑哪些方面
  • 网站怎么做域名跳转网站点击快速排名
  • 建一个快讯网站要多少钱搜索引擎网络排名
  • 深圳做网站的网络公seo技术优化服务
  • 浙江建设职业技术学院提前招网站推广app用什么平台比较好
  • 网站诊断网站seo诊断搜索引擎排名机制
  • 做装饰网站公司互联网营销推广渠道
  • 做软件开发的哪个招聘网站比较靠谱在线生成个人网站app
  • wordpress.org hostingseo怎么优化
  • 人民日报客户端上海频道广东seo网络培训
  • 网站建设和运维昆明新闻头条最新消息
  • 网站服务器ip地址怎么查seo关键词推广多少钱
  • 免费网站制作公司全球网络营销公司排行榜