spark streaming wordcount
package com.spark.streaming
import org.apache.spark.SparkConf
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.Seconds
object WordCount {
def main(args: Array[String]): Unit = {
val conf = new SparkConf()
.setMaster("local[2]")
.setAppName("WordCount")
val ssc = new StreamingContext(conf,Seconds(5))
val lines = ssc.socketTextStream("spark1", 9999)
val wordCounts = lines.flatMap { _ .split(" ") }
.map { word => (word,1) }
.reduceByKey(_+_)
wordCounts.print()
ssc.start()
ssc.awaitTermination()
}
}