Skip to content

Instantly share code, notes, and snippets.

@toff63
Last active October 26, 2015 11:32
Show Gist options
  • Save toff63/3e9a5a1b71258e276ade to your computer and use it in GitHub Desktop.
Save toff63/3e9a5a1b71258e276ade to your computer and use it in GitHub Desktop.
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