SparkStreaming

/////、、、

import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.{SparkConf, SparkContext}

object StreamingWC {
  def main(args: Array[String]): Unit = {
    //  StreamingContext
    val conf = new SparkConf().setAppName("StreamingWC").setMaster("local[2]")
    val sc = new SparkContext(conf)
    val ssc = new StreamingContext(sc, Seconds(5))

    val ds = ssc.socketTextStream("100.168.1.182", 8888)
    val result = ds.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_+_)

    result.print()
    ssc.start()
    ssc.awaitTermination()
  }
  
}

 

你可能感兴趣的:(Spark)