SparkStreaming 的编程模型

依赖管理

基本套路

Dstream输入源 ---input DStream

Dstream输入源--- Receiver

内置的input Dstream : Basic Source

内置的input Dstream :Advanced Sources

Dstream 输入源: multiple input DStream

Dstream 输入源: Custom Receiver

官方参考网站 http://spark.apache.org/docs/1.6.2/streaming-custom-receivers.html
scala 参考模版
class CustomReceiver(host: String, port: Int)
extends Receiver[String](StorageLevel.MEMORY_AND_DISK_2) with Logging { def onStart() {
// Start the thread that receives data over a connection
new Thread("Socket Receiver") {
override def run() { receive() }
}.start()
} def onStop() {
// There is nothing much to do as the thread calling receive()
// is designed to stop by itself if isStopped() returns false
} /** Create a socket connection and receive data until receiver is stopped */
private def receive() {
var socket: Socket = null
var userInput: String = null
try {
// Connect to host:port
socket = new Socket(host, port) // Until stopped or connection broken continue reading
val reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"))
userInput = reader.readLine()
while(!isStopped && userInput != null) {
store(userInput)
userInput = reader.readLine()
}
reader.close()
socket.close() // Restart in an attempt to connect again when server is active again
restart("Trying to connect again")
} catch {
case e: java.net.ConnectException =>
// restart if could not connect to server
restart("Error connecting to " + host + ":" + port, e)
case t: Throwable =>
// restart if there is any other error
restart("Error receiving data", t)
}
}
}
java 参考模版
public class JavaCustomReceiver extends Receiver<String> {
String host = null;
int port = -;
public JavaCustomReceiver(String host_ , int port_) {
super(StorageLevel.MEMORY_AND_DISK_2());
host = host_;
port = port_;
}
public void onStart() {
// Start the thread that receives data over a connection
new Thread() {
@Override public void run() {
receive();
}
}.start();
}
public void onStop() {
// There is nothing much to do as the thread calling receive()
// is designed to stop by itself if isStopped() returns false
}
/** Create a socket connection and receive data until receiver is stopped */
private void receive() {
Socket socket = null;
String userInput = null;
try {
// connect to the server
socket = new Socket(host, port);
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
// Until stopped or connection broken continue reading
while (!isStopped() && (userInput = reader.readLine()) != null) {
System.out.println("Received data '" + userInput + "'");
store(userInput);
}
reader.close();
socket.close();
// Restart in an attempt to connect again when server is active again
restart("Trying to connect again");
} catch(ConnectException ce) {
// restart if could not connect to server
restart("Could not connect", ce);
} catch(Throwable t) {
// restart if there is any other error
restart("Error receiving data", t);
}
}
}
无状态的转换操作

有状态的转换操作1-updateStateByKey

有状态的转换操作2-window


有状态的转换操作2-window普通规约与增量规约

理解增量规约

输出操作
Dstream输出

持久化操作

SparkStreaming 的编程模型的更多相关文章
- Spark:Spark 编程模型及快速入门
http://blog.csdn.net/pipisorry/article/details/52366356 Spark编程模型 SparkContext类和SparkConf类 代码中初始化 我们 ...
- JS魔法堂:深究JS异步编程模型
前言 上周5在公司作了关于JS异步编程模型的技术分享,可能是内容太干的缘故吧,最后从大家的表情看出"这条粉肠到底在说啥?"的结果:(下面是PPT的讲义,具体的PPT和示例代码在h ...
- 多线程之异步编程: 经典和最新的异步编程模型,async与await
经典的异步编程模型(IAsyncResult) 最新的异步编程模型(async 和 await) 将 IAsyncInfo 转换成 Task 将 Task 转换成 IAsyncInfo 示例1.使用经 ...
- 多线程之异步编程: 经典和最新的异步编程模型, IAsyncInfo 与 Task 相互转换
经典的异步编程模型(IAsyncResult) 最新的异步编程模型(async 和 await) 将 IAsyncInfo 转换成 Task 将 Task 转换成 IAsyncInfo 示例1.使用经 ...
- jQuery插件编写及链式编程模型小结
JQuery极大的提高了我们编写JavaScript的效率,让我们可以愉快的编写代码,做出各种特效.大多数情况下,我们都是使用别人开发的JQuery插件,今天我们就来看看如何把我们常用的功能做出JQu ...
- 云巴:基于MQTT协议的实时通信编程模型
概要 有人常问,云巴实时通信系统到底提供了一种怎样的服务,与其他提供推送或 IM 服务的厂商有何本质区别.其实,从技术角度分析,云巴与其它同类厂商都是面向开发者的通信服务,宏观的编程模型都是大同小异, ...
- 第3章 窗口与消息_3.1Windows编程模型
第3章窗口与消息 3.1 Windows_编程模型 (1)窗口程序的运行过程 ①设计窗口 ②注册窗口类(RegisterClassEx).在注册之前,要先填写RegisterClassEx的参 ...
- MFC-01-Chapter01:Hello,MFC---1.1 Windows 编程模型
1.1 Windows编程模型 为传统的操作系统编写的程序使用的是过程化模型,即程序从头到尾按顺序执行.例如C程序,从main函数入口开始执行,中间调用不同的函数一直到程序结束返回,这种过程是程序本身 ...
- 金蝶 K/3 Cloud 服务端控件编程模型
如下图是服务端已有的控件编程模型
随机推荐
- JavaScript权威指南——词法结构(4)
标识符和保留字 1.标识符 标识符就是一个名字.在JavaScript中,标识符用来给变量.属性.函数和参数进行命名,或者用做某些循环语句中的跳转位置的标记. //变量 var identifier ...
- SWIFT解析天气JSON格式
访问以下链接可以得到京城当天的天气:http://www.weather.com.cn/adat/sk/101010100.html 返回的JSON格式如下: {"weatherinfo&q ...
- jmeter随笔(34)-WebSocket协议接口测试实战
2017年春节结束了,一切再次回归到正轨,我们飞测也开始继续分享,小怪在这里预祝大家在2017年工作顺利,满满的收获. 背景:今天研发哥们QQ我,请教websocket协议的接口测试,这哥们自己开发了 ...
- U盘安装电脑系统教程
[怎么使用u盘安装系统.U盘装系统.如何用U盘安装系统.U盘制作系统.U盘引导.U盘启动.U盘量产.安装系统.如何设置U盘启动] 在电脑系统的日常使用中,经常会遇到系统崩溃或重新安装系统的情况,没有光 ...
- Java乱码解决之道
1.常见字符编码 ASCII编码: ASCII,American Standard Code for Information Interchange,是基于拉丁字母的一套电脑编码系统,主要用于显示现代 ...
- ACM中的取模
取模本身的性质:(之前有一篇博客写过)三则运算(+,-,*)过程中的取模与最后的取模一样(前提是最后不超long long(或int) 范围,所以为防止超范围,直接对三则运算中的过程取模) 然后就是A ...
- spring boot redis -> @Cacheable,@CacheEvict, @CachePut
https://blog.csdn.net/eumenides_/article/details/78298088?locationNum=9&fps=1 https://www.cnblog ...
- width百分比
table中的td可以在页面中直接在元素上设置width:但是li不能只能在页面中写style: <!-- <li width="20%" class="p- ...
- timescaledb 集成prometheus
timescaledb 1.0 已经发布了,同时支持prometheus 使用doker-compose 运行 环境准备 docker-compose 文件 version: '2.1' servic ...
- zeroMQ 学习
zeroMQ 是一个高性能的分布式设计的消息队列,网上有人进行过性能的比较,非常厉害,并且很大约40多种语言的API 可以调用,真实很不错的. 而且有一点就是使用简单,不需要服务器,对于使用C/C++ ...