sparkstreaming官方文档笔记
来源:互联网 发布:联通 暂停数据流量 编辑:程序博客网 时间:2024/05/22 15:30
1、sparksteaming 入门例子
注:代码摘自spark官方文档 http://spark.apache.org/docs/latest/streaming-programming-guide.html#a-quick-example
import org.apache.spark._import org.apache.spark.streaming._import org.apache.spark.streaming.StreamingContext._ // not necessary since Spark 1.3// Create a local StreamingContext with two working thread and batch interval of 1 second.// The master requires 2 cores to prevent from a starvation scenario.val conf = new SparkConf().setMaster("local[2]").setAppName("NetworkWordCount")val ssc = new StreamingContext(conf, Seconds(1))
// Create a DStream that will connect to hostname:port, like localhost:9999val lines = ssc.socketTextStream("localhost", 9999)
// Split each line into wordsval words = lines.flatMap(_.split(" "))
import org.apache.spark.streaming.StreamingContext._ // not necessary since Spark 1.3// Count each word in each batchval pairs = words.map(word => (word, 1))val wordCounts = pairs.reduceByKey(_ + _)// Print the first ten elements of each RDD generated in this DStream to the consolewordCounts.print()
ssc.start() // Start the computationssc.awaitTermination() // Wait for the computation to terminate
然后,开启一个终端窗口,作为数据源输入: nc -lk 9999 进入spark环境目录,执行workcount实时统计例子: ./bin/run-example org.apache.spark.examples.streaming.NetworkWordCount localhost 9999
2、DStream 数据源
1)、TCP scoket
如上例子;
通过StreamingContext API 读取文件数据源streamingContext.textFileStream(dataDirectory)
2)、Advanced Sources
也可以从kafka、flume、kinesis(这个工作中还真没使用过)消费数据,这也是典型的sparkstreaming实时处理流程;
3)、Custom Sources
根据业务场景定制数据源;
之前工作涉及浅显的spark技术,由于最近工作也不怎么用,工作之余,就重新学习一下,共勉!
阅读全文
0 0
- sparkstreaming官方文档笔记
- SparkStreaming笔记
- Swift 官方文档笔记
- unity官方文档笔记
- Django官方文档笔记
- OpenStack官方文档研究笔记
- RakNet官方文档学习笔记
- maven官方文档阅读笔记
- UINavigationController官方文档学习笔记
- Akka Acto官方文档笔记
- spring 官方文档,学习笔记
- tkinter官方文档学习笔记
- yii2.0官方文档笔记
- spring boot 官方文档笔记
- libevent官方文档学习笔记
- Java8官方文档学习笔记
- Vue-router 官方文档笔记
- 云笔记官方使用说明文档
- C/C++ Windows移植到Linux兼容库移植
- [译]对design库中AppBarLayout嵌套滚动问题的修复
- Android 可拖拽的GridView效果实现, 长按可拖拽和item实时交换
- jq 使用history事件后退,将当前页面数据放入数据库
- 用cxf生成webservice的java客户端代码
- sparkstreaming官方文档笔记
- 高级机器学习算法工程师--【北京】
- java iterator
- ArcGis for Android shp
- c#--类型参考表
- 【深度干货】2017年深度学习优化算法研究亮点最新综述(附slide下载)
- ThreadLocal设计模式
- js 运算保留小数位
- springboot之mongoDB项目Exception in monitor thread while connecting to server localhost:27017