Flink的处理流程
一 从集合读取数据
import bag.day01.SensorReading
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
//提供隐式转换
import org.apache.flink.api.scala._
object CollectionSuource {
def main(args: Array[String]): Unit = {
val env =StreamExecutionEnvironment.getExecutionEnvironment
//设置并行度
env.setParallelism(1)
//读取集合数据
val stream1 = env .fromCollection(
List( SensorReading("sensor_1", 1547718199, 35.8),
SensorReading("sensor_6", 1547718201, 15.4),
SensorReading("sensor_7", 1547718202, 6.7),
SensorReading("sensor_10", 1547718205, 38.1) ))
stream1.print()
env.execute()
}
}
二 从文件读取
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.api.scala._
object FileSource {
def main(args: Array[String]): Unit = {
val env =StreamExecutionEnvironment.getExecutionEnvironment
env.setParallelism(1)
val read_text = env.readTextFile("C:\\Users\\Administrator\\Desktop\\文档\\01.tx