[英]Apache Storm: Ack not working
I am trying to implement the guaranteed message processing but the ack or fail methods on the Spout are not being called. 我正在尝试实现保证的消息处理,但是未调用Spout上的ack或fail方法。
I am passing the a message ID object with the spout. 我正在通过喷口传递消息ID对象。 I am passing the tuple with each bolt and calling collector.ack(tuple) in each bolt. 我通过每个螺栓传递元组,并在每个螺栓中调用collector.ack(tuple)。
Question The ack or fail is not being called and I cannot work out why? 问题没有得到确认或失败,我无法弄清楚为什么?
Here is a shortened code sample. 这是一个缩短的代码示例。
Spout Code using BaseRichSpout 使用BaseRichSpout的Spout代码
public void nextTuple() {
for( String usage : usageData ) {
.... further code ....
String msgID = UUID.randomUUID().toString()
+ System.currentTimeMillis();
Values value = new Values(splitUsage[0], splitUsage[1],
splitUsage[2], msgID);
outputCollector.emit(value, msgID);
}
}
@Override
public void ack(Object msgId) {
this.pendingTuples.remove(msgId);
LOG.info("Ack " + msgId);
}
@Override
public void fail(Object msgId) {
// Re-emit the tuple
LOG.info("Fail " + msgId);
this.outputCollector.emit(this.pendingTuples.get(msgId), msgId);
}
Bolt Code using BaseRichBolt 使用BaseRichBolt的Bolt代码
@Override
public void execute(Tuple inputTuple) {
this.outputCollector.emit(inputTuple, new Values(serverData, msgId));
this.outputCollector.ack(inputTuple);
}
Final Bolt 最终螺栓
@Override
public void execute(Tuple inputTuple) {
..... Simply reports does not emit .....
this.outputCollector.ack(inputTuple);
} }
The reason the ack did not work was the use of the for loop in the spout. ack不起作用的原因是在喷嘴中使用了for循环。 Changed this to a counter loop version below the emit and it works. 将其更改为发出以下的计数器循环版本,并且可以工作。
Example 例
index++;
if (index >= dataset.size()) {
index = 0;
}
Further to this thanks to the mailing list info. 除此之外,还要感谢邮件列表信息。 Its because the Spout runs on a single thread and will block in a for loop, as next tuple will not return therefore it will never be able to call ACK method. 这是因为Spout在单个线程上运行,并且将在for循环中阻塞,因为下一个元组将不会返回,因此它将永远无法调用ACK方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.