Skip to content

Instantly share code, notes, and snippets.

@diogoaurelio
Last active September 4, 2016 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogoaurelio/e948547ed23001281805b4463bc05872 to your computer and use it in GitHub Desktop.
Save diogoaurelio/e948547ed23001281805b4463bc05872 to your computer and use it in GitHub Desktop.
package com.berlinsmartdata.spark.streaming
import org.apache.spark._
import org.apache.spark.streaming._
import org.apache.spark.streaming.StreamingContext._
object Sample {
def main(args: Array[String]):Unit = {
val numReceivers = 2 //note: has to be >= 2
val conf = new SparkConf().setMaster(s"local[${numReceivers}]").setAppName("YetAnotherWordCountExample")
val ssc = new StreamingContext(conf, Seconds(1))
val lines = ssc.socketTextStream("localhost", 9999)
val wordCounts = lines.flatMap(_.split(" ")).map(word => (word, 1)).reduceByKey(_+_)
wordCounts.print() //output operation is this
ssc.start()
ssc.awaitTermination()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment