flink-侧输出流无法输出警告信息,犯的低级错误,写在这里,警告自己

代码如下

使用scala书写

import org.apache.flink.streaming.api.TimeCharacteristic
import org.apache.flink.streaming.api.functions.ProcessFunction
import org.apache.flink.streaming.api.scala._
import org.apache.flink.util.Collector
/**
  * author : wyan
  * create : 
  * desc : 通过侧输出流发出警告
  */
object SideOutputs {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)
    env.setParallelism(1)
    val readings: DataStream[SensorReading] = env
      .addSource(new SensorSource)
      .process(new FreezingMonitor)
    //主流
//    readings.print()
    //侧输出流
    val side: DataStream[String] = readings
      .getSideOutput(new OutputTag[String]("freezingAlarmOutput"))
    side.print()

    env.execute()
  }
}

class FreezingMonitor extends ProcessFunction[SensorReading,SensorReading]{
  //定义侧输出标签
  lazy val freezingAlarmOutput : OutputTag[String] = new OutputTag[String]("freezing-alarms")

  override def processElement(r: SensorReading,
                              ctx: ProcessFunction[SensorReading, SensorReading]#Context,
                              out: Collector[SensorReading]): Unit = {
    if (r.temperature > 32.0) {
      ctx.output(freezingAlarmOutput,s"=========freezing alarm for ${r.id}")
    }

    out.collect(r)
  }
}

问题

flink-侧输出流无法输出警告信息,犯的低级错误,写在这里,警告自己_第1张图片执行时侧输出流未输出任何数据

解决

flink-侧输出流无法输出警告信息,犯的低级错误,写在这里,警告自己_第2张图片
将freezingAlarmOutput 改为freezing-alarms

执行结果

flink-侧输出流无法输出警告信息,犯的低级错误,写在这里,警告自己_第3张图片

总结

犯了要给低级错误,主要还是自己理解有误,导致编码时书写就错了,花了一个小时找出的,真是浪费时间

你可能感兴趣的:(flink)