2、Storm中的一些概念理解
1、Tuple,Value,Field
Tuple官方解释:
“A tuple is a named of values where each value can be any type.”
tuple是一个类似于列表的东西,存储的每个元素叫做field(字段),可以是任何类型。
Storm使用tuple作为它的数据模型, 每个tuple是一堆值,每个值都有一个名字,
一个Tuple代表数据流中的一个基本处理单元,
例如:一条cookie日志,它可以包含多个Field, 每个Field表示一个属性。
Tuple本应该是一个Key-Value的Map, 由于各个组件之间的传递的tuple字段名称已经实现预定好了,
所以Tuple只需要按序填入各个Value,所以就是一个Value List。
一个没有边界、源源不断的Tuple序列就组成了Stream。
topology里面的每个节点,必须定义它要发射的Tuple的每个字段
例如下面这个bolt定义它所发射的tuple包含两个字段,类型分别为double,triple。
declareOutputFields方法定义要输出的字段 : [“double”, “triple”]。
public class DoubleAndTripleBolt implements IRichBolt {
private OutputCollector _collector;
@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
_collector = collector;
}
@Override
public voide xecute(Tuple input) {
int val = input.getInteger(0);
_collector.emit(input,new Values(val*2, val*3));
_collector.ack(input);
}
@Override
public void cleanup() {
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("double","triple"));
}
}
declareOutputFields方法定义要输出的字段 : [“sentence”]。
public class RandomSentenceSpout extends BaseRichSpout {
//用来收集Spout输出的tuple
private SpoutOutputCollector collector;
private Random random;
//该方法调用一次,主要由storm框架传入SpoutOutputCollector
@Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
this.collector = collector;
random = new Random();
//连接kafka mysql ,打开本地文件
}
/**
* 上帝之手
* while(true)
* spout.nextTuple()
*/
@Override
public void nextTuple() {
String[] sentences = new String[]{
"the cow jumped over the moon","the dog jumped over the moon",
"the pig jumped over the gun","the fish jumped over the moon","the duck jumped over the moon",
"the man jumped over the sun","the girl jumped over the sun","the boy jumped over the sun"
};
String sentence = sentences[random.nextInt(sentences.length)];
collector.emit(new Values(sentence));
System.out.println("RandomSentenceSpout 发送数据:"+sentence);
}
//消息源可以发射多条消息流stream
@Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
outputFieldsDeclarer.declare(new Fields("sentence"));
}
}
2、Storm中的一些概念理解的更多相关文章
- Storm中并发程度的理解
Storm中涉及到了很多组件,例如nimbus,supervisor等等,在参考了这两篇文章之后,对这个有了更好的理解. Understanding the parallelism of a Stor ...
- ubuntn系统下将文件拷贝到优盘中及挂载概念理解
参考资料:http://jingyan.baidu.com/article/7082dc1c76f178e40a89bdd3.html: http://bbs.csdn.net/topics/3801 ...
- storm中的一些概念
1.topology 一个topolgy是spouts和bolts组成的图,通过stream groupings将图中的spout和bolts连接起来:如图所示: 一个topology会一直运行知道你 ...
- storm中的基本概念
Storm是一个流计算框架,处理的数据是实时消息队列中的,所以需要我们写好一个topology逻辑放在那,接收进来的数据来处理,所以是通过移动数据平均分配到机器资源来获得高效率. Storm的优点是全 ...
- Java基础中的一些概念理解
同步 和 异步区别 同步和异步通常用来形容一次方法的调用. 同步方法调用一旦开始,调用者必须等到方法调用返回后,才能继续后续的行为.而异步方法调用更像一个消息传递,一旦开始,方法调用就会立即返回,调用 ...
- storm中几个概念的大小关系
从图可以看出来:topology>supervisor>worker>excutor>task; 也就是说一个topology可以运行在多个supervisor上,一个supe ...
- 关于Storm 中Topology的并发度的理解
来自:https://storm.apache.org/documentation/Understanding-the-parallelism-of-a-Storm-topology.html htt ...
- OpenStack中Keystone的基本概念理解
原文http://www.kankanews.com/ICkengine/archives/10788.shtml Keystone简介 Keystone(OpenStack Identity Ser ...
- storm源码之理解Storm中Worker、Executor、Task关系 + 并发度详解
本文导读: 1 Worker.Executor.task详解 2 配置拓扑的并发度 3 拓扑示例 4 动态配置拓扑并发度 Worker.Executor.Task详解: Storm在集群上运行一个To ...
随机推荐
- vim编辑器显示行号
Vim编辑器显示行号的设置 1. 显示行号 :set nu 2. 不显示行号 :set nonu :set nu :set nonu
- 宝塔linux面版安装网站环境 自动化
[root@localhost ~]# yum install -y wget && wget -O install.sh http://download.bt.cn/install/ ...
- day29 二十九、元类、单例
一.eval.exec内置函数 1.eval函数 eval内置函数的使用场景: ①执行字符串会得到相应的执行结果 ②一般用于类型转换得到dict.list.tuple等 2.exec函数 exec应用 ...
- racket安装
https://www.cnblogs.com/scige/p/3379447.html
- Multi-Projector Based Display Code ---- FAQ
Frequently Asked Question How do I know that my camera has a proper lens? Answer: If you can see exa ...
- go/wiki/MutexOrChannel Golang并发:选channel还是选锁?
https://mp.weixin.qq.com/s/JcED2qgJEj8LaBckVZBhDA https://github.com/golang/go/wiki/MutexOrChannel M ...
- 安卓点击home键重启
主要原因是:每次启动Intent导致新创建Task的时候,该Task会记录导致其创建的Intent:而如果后续需要有一个新的与创建Intent完全一致(完全一致定位为:启动类,action.categ ...
- 管理npm源命令
nrm ls 查看源镜像 nrm add 自定义名称 源地址 nrm use 自定义名称
- 转 linux安装jdk环境(多种方式)
linux系统通用安装通过tar.gz压缩包安装此方法适用于绝大部分的linux系统 1.先下载tar.gz的压缩包,这里使用官网下载. 进入: http://www.oracle.com/techn ...
- 博客搬家 https://hanwang945.github.io/
博客搬家 https://hanwang945.github.io/