Flink —— DataStream API
Posted 清泉白石
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flink —— DataStream API相关的知识,希望对你有一定的参考价值。
package flink
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.api.scala._
case class SensorReading(id: String, timestamp: Long, temperature: Double)
object SourceTest {
def main(args: Array[String]): Unit = {
val env = StreamExecutionEnvironment.getExecutionEnvironment
// 1.从自定义的集合中读取数据
val list = List(
SensorReading("sensor1", 153242, 35.8),
SensorReading("sensor2", 153222, 15.4),
SensorReading("sensor3", 153142, 6.7),
SensorReading("sensor4", 151242, 38.7))
val stream1 = env.fromCollection(list)
stream1.print("stream1").setParallelism(1)
env.execute("source test")
}
}
以上是关于Flink —— DataStream API的主要内容,如果未能解决你的问题,请参考以下文章
Apache Flink -Streaming(DataStream API)