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 服务端控件编程模型
如下图是服务端已有的控件编程模型
随机推荐
- chapter02 svm对手写体数字的数码图像进行识别
#coding=utf8 # 从sklearn.datasets里导入手写体数字加载器. from sklearn.datasets import load_digits # 从sklearn.cro ...
- Adobe Flash Player - imsoft.cnblogs
Adobe Flash Player是一个跨平台.基于浏览器的应用程序.运行时,它可以跨屏幕和浏览器原汁原味地查看具有表现力的应用程序.内容和视频.Flash Player实现了移动屏幕上的高性能优化 ...
- hdu2068 RPG的错排 组合数/递推
#include<stdio.h> ]; long long c(int a,int b) { ,j; ;i>=a-b+,j<=b;i--,j++) sum=sum*i/j; ...
- SPOJCOT2 Count on a tree II
分析 树上莫队裸题. 好博客 树剖的时候不能再次dfs重儿子.(好像是废话,但我因为这个问题调了三小时) 代码 #include<cstdlib> #include<cstdio&g ...
- LG3377 【模板】左偏树(可并堆)
好博客 1 2 上面那个用数组写的跑的快,且便于封装,就用他的代码了. 代码 #include<cstdlib> #include<cstdio> #include<cm ...
- MySQL命令行--导入导出数据库
MySQL命令行导出数据库: 1,进入MySQL目录下的bin文件夹:cd MySQL中到bin文件夹的目录 如我输入的命令行:cd C:\Program Files\MySQL\MySQL Se ...
- ThinkPHP5 控制器中怎么实现 where id = 2 or id = 3 这个查询语句?
使用 whereOr whereIn(); (来自 ★C̶r̶a̶y̶o̶n-杭州 ) 为什么不用数组啊,array('eq', array(1,2),'or') (来自 supler)
- Oracle RAC 归档 与 非归档 切换
Oracle 的生产库都是启动在归档模式下,RAC下归档非归档的切换和单实例也是一样的,都是在MOUNT模式下执行ALTER DATABASE ARCHIVELOG/NOARCHIVELOG;命令. ...
- centos6 安装GitLab
环境 Requirements 软件 版本CentOS 6.6Python 2.6Ruby 2.1.5Git 1.7.10+Redis 2.0+MySQL GitLab 7-8-stableGitLa ...
- Oracle Grid control 11g及Active DataGuard 11g安装部署
Oracle Grid control 11g及Active DataGuard 11g安装部署(一) 原贴 http://blog.csdn.net/lichangzai/article/detai ...