Spark Streaming 监控通过 nc -lk 9999 命令发送的word计数

package org.lm.spark.streaming

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

object SparkStreamingQucikOps {
  def main(args: Array[String]): Unit = {
    val conf=new SparkConf().setAppName("Spark Streaming Qucik Ops").setMaster("spark://192.168.189.128:7077")
    val ssc=new StreamingContext(conf,Seconds(5))
    val lines=ssc.socketTextStream("192.168.189.129",9999)
    val words=lines.flatMap(line=>line.split(" "))
    val pairs=words.map(word=>(word,1))
    val wordcount=pairs.reduceByKey(_+_)
    wordcount.print()
    ssc.start()
    ssc.awaitTermination()

  }

}

你可能感兴趣的:(Spark Streaming 监控通过 nc -lk 9999 命令发送的word计数)