文章23 | 阅读 14967 | 点赞0
package com.gosuncn
import org.apache.flink.streaming.api.scala._
object WordCountStreamingJob {
def main(args: Array[String]) {
val env = StreamExecutionEnvironment.getExecutionEnvironment
// lines.flatMap(_.split(" ")).map((_, 1)).keyBy(0).sum(1).print()
val lines: DataStream[String] = env.socketTextStream("47.52.74.183", 8888)
val words: DataStream[String] = lines.flatMap(_.split(" "))
val wordAndOne: DataStream[(String, Int)] = words.map((_, 1))
val summed: DataStream[(String, Int)] = wordAndOne.keyBy(0).sum(1)
summed.print()
env.execute("WordCountStreamingJob")
}
}
内容来源于网络,如有侵权,请联系作者删除!