08_Flink底层API

ProcessFuntion是一个地接的流处理操作,它可以访问流处理程序的基础构建模块:

  • 事件(event流元素)
  • 状态(state 容错性,一致性,仅在keyed stream中)
  • 定时器(times)(event time,processing time ,仅在keyed stream中)

ProcessFuntion中,可以通过getRuntimeContext()访问keyed state,实则就是我们存储的状态变量;在processElement()函数中获取Context对象,通过Context可以访问event timestamp。还可以注册TimeService,TimeService可以用于为将来的event/process time瞬间注册回调,回调调用时,会触发onTime()函数的调用:

import org.apache.flink.api.common.state.{ValueState, ValueStateDescriptor}
import org.apache.flink.api.java.functions.KeySelector
import org.apache.flink.configuration.Configuration
import org.apache.flink.streaming.api.TimeCharacteristic
import org.apache.flink.streaming.api.functions.ProcessFunction
import org.apache.flink.streaming.api.functions.source.SourceFunction
import org.apache.flink.streaming.api.functions.timestamps.AscendingTimestampExtractor
import org.apache.flink.streaming.api.scala._
import org.apache.flink.util.Collector


/**
  * 每1

猜你喜欢

转载自blog.csdn.net/qq285016127/article/details/105172311