Skip to content

Instantly share code, notes, and snippets.

@praveend
Created January 14, 2016 05:52
Show Gist options
  • Select an option

  • Save praveend/2ca728ca3839a09875e1 to your computer and use it in GitHub Desktop.

Select an option

Save praveend/2ca728ca3839a09875e1 to your computer and use it in GitHub Desktop.
/**
* Created by praveendevarao on 12/01/16.
*/
import org.apache.spark._
import org.apache.spark.storage.StorageLevel
import org.apache.spark.streaming._
import org.apache.spark.streaming.StreamingContext._
object WordCount {
def main(args: Array[String]) {
val conf = new SparkConf().setMaster("local[*]").setAppName("streamapp")
conf.set("spark.streaming.concurrentJobs","2")
val ssc = new StreamingContext(conf, Seconds(1))
val lines = ssc.socketTextStream("localhost", 9999, StorageLevel.MEMORY_AND_DISK_SER)
//val lines1 = ssc.socketTextStream("localhost", 8888, StorageLevel.MEMORY_AND_DISK_SER)
val words = lines.flatMap(_.split(" "))
val wordCounts = words.map(x => (x, 1)).reduceByKey(_ + _)
wordCounts.print()
ssc.start()
ssc.awaitTermination()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment