Spark Streaming之使用Spark Streaming处理文件系统(local/hdfs)的数据
2018-02-17 23:25
585 查看
package com.yys.spark.project
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:///opt/yys/data/")
val result = lines.flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_)
result.print()
ssc.start()
ssc.awaitTermination()
}
}
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:///opt/yys/data/")
val result = lines.flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_)
result.print()
ssc.start()
ssc.awaitTermination()
}
}
相关文章推荐
- Spark 实战, 第 2 部分:使用 Kafka 和 Spark Streaming 构建实时数据处理系统
- 在使用Spark Streaming向HDFS中保存数据时,文件内容会被覆盖掉的解决方案
- 使用 Kafka 和 Spark Streaming 构建实时数据处理系统
- 使用 Kafka 和 Spark Streaming 构建实时数据处理系统(转)
- 使用 Kafka 和 Spark Streaming 构建实时数据处理系统
- 使用 Kafka 和 Spark Streaming 构建实时数据处理系统
- Spark 实战, 第 2 部分:使用 Kafka 和 Spark Streaming 构建实时数据处理系统
- 第96讲 通过Spark Streaming的foreachRDD把处理后的数据写入外部存储系统(数据库)中
- spark流数据处理:Spark Streaming的使用
- Spark Streaming使用Kafka保证数据零丢失
- 大数据IMF传奇行动绝密课程第83课:透彻讲解使用Scala和Java两种方式实战Spark Streaming开发
- flume + kafka + sparkStreaming + HDFS 构建实时日志分析系统
- 大数据IMF传奇行动绝密课程第85课:基于HDFS的SparkStreaming案例实战和内幕源码解密
- 记录一下SparkStreaming中因为使用redis做数据验证而导致数据结果不对的问题
- flume + kafka + sparkStreaming + HDFS 构建实时日志分析系统
- 使用Flume+Logstash+Kafka+Spark Streaming进行实时日志处理分析【公安大数据】
- 使用Spark Streaming处理爬取的数据(问题总结)
- Spark Streaming使用Kafka保证数据零丢失
- Spark Streaming使用Kafka保证数据零丢失
- 第96课: 通过Spark Streaming的foreachRDD把处理后的数据写入外部存储系统中