Last active
October 26, 2015 11:32
-
-
Save toff63/3e9a5a1b71258e276ade to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.spark._ | |
import org.apache.spark.streaming._ | |
import org.apache.spark.SparkConf | |
object SimpleStreamingApp { | |
def main(args:Array[String]) { | |
val conf = new SparkConf().setMaster("local[2]").setAppName("Simple App") | |
val ssc = new StreamingContext(conf, Seconds(45)) // Time window of 45 second. | |
val lines = ssc.socketTextStream("localhost", 9999) | |
val words = lines.flatMap(_.split(" ")) | |
val pairs = words.map(word => (word, 1)) | |
val wordCount = pairs.reduceByKey(_+_) | |
wordCount.print() | |
ssc.start() | |
ssc.awaitTermination() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment