【问题标题】:how to identify If all the emits reached the bolt?如何识别是否所有的发射都到达了螺栓?
【发布时间】:2015-10-23 13:38:33
【问题描述】:
我有一个 kafka spout 说 KafkaSpout,它从 kafka 主题读取消息说 msg 并发出一个螺栓说 Bolt1。 Bolt1 将此消息拆分为多个消息 msg1、msg2、..、msgN 并发送到其他 Bolt 说 螺栓2。现在,一旦来自 Bolt1 的所有消息 msg1、msg2、..、msgN 都发送到 Bolt2 ,我需要对msg做一些处理。有什么方法可以识别是否所有拆分消息都到达 Bolt2 ?
【问题讨论】:
标签:
java
apache-kafka
apache-storm
【解决方案1】:
阅读 Apache Storm 的 Guaranteeing Message Processing 文档页面,它谈到如果正确发出,将生成一个元组树,如果消息丢失,Storm 将从 Spout 重播。
这是通过 Storm 调用锚定的机制发生的,假设您有以下执行方法。
public void execute(Tuple tuple) {
String sentence = tuple.getString(0);
for(String word: sentence.split(" ")) {
_collector.emit(tuple, new Values(word)); //anchoring happening
}
_collector.ack(tuple);
}
通过将输入元组指定为第一个来锚定每个单词元组
发射的论据。由于单词 tuple 是锚定的,所以 spout tuple 在
如果单词 tuple 稍后将重播树的根
下游处理失败。 link
而如果你发出的新词不包括原始元组,
_collector.emit(new Values(word)); //no anchoring
以这种方式发出单词 tuple 会导致它被取消锚定。如果
下游处理元组失败,根元组不会被处理
重播。 link