其他sparkStreaming项目案例地址:(建议每一个都是熟知)
https://github.com/apache/spark/tree/master/examples/src/main/scala/org/apache/spark/examples/streaming
sparkStreaming处理文件系统数据(local/hdfs):
package com.imooc.spark import org.apache.spark.SparkConf import org.apache.spark.streaming.{Seconds, StreamingContext} /** * 使用Spark Streaming处理文件系统(local/hdfs)的数据 */ object FileWordCount { def main(args: Array[String]): Unit = { val sparkConf = new SparkConf().setMaster("local").setAppName("FileWordCount") val ssc = new StreamingContext(sparkConf, Seconds(5)) val lines = ssc.textFileStream("file:///Users/rocky/data/imooc/ss/") val result = lines.flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_) result.print() ssc.start() ssc.awaitTermination() } }