直接上代码吧
说下测试思路:
该代码监控的/tmp/sparkStream/目录;
首先,创建该目录mkdir -p /tmp/sparkStream;
然后,运行spark程序;
最后,向监控目录/tmp/sparkStream/添加数据文件;
观察spark程序运行效果。
sparkStreaming import org.apache.log4j.{LoggerLevel} import org.apache.spark.SparkConf import org.apache.spark.streaming.{SecondsStreamingContext} import org.apache.spark.streaming.StreamingContext._ object HdfsWordCount { def main(args: Array[]){ Logger.getLogger("org.apache.spark").setLevel(Level.WARN) Logger.getLogger("org.apache.eclipse.jetty.server").setLevel(Level.OFF) sparkConf = SparkConf().setAppName().setMaster() ssc = StreamingContext(sparkConf()) lines = ssc.textFileStream() words = lines.flatMap(_.split()) wordCounts = words.map(x=>(x)).reduceByKey(_+_) wordCounts.print() ssc.start() ssc.awaitTermination() } }
原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/tech/opensource/185410.html