1.spout中nextTuple方法中發送的tuple需要攜帶msgId
collector.emit(new Values(line),index); //index爲Integer類型
2.bolt中需要對tuple進行確認(ack() | fail())public void execute(Tuple tuple) {
String line = tuple.getString(0);
System.out.println(this + " : " + line);
if(new Random().nextBoolean()){
//確認,向上家(也就是Spout)回執成功
collector.ack(tuple);}
else{
//失敗,向上家(也就是Spout)回執失敗
collector.fail(tuple);}
}
3.實現spout的ack()和fail()方法
//下家(Bolt)接收成功處理
System.out.println(this + " : ack() : " + msgId);
}
//下家(Bolt)接收失敗處理
public void fail(Object msgId) {
System.out.println(this + " : fail() : " + msgId);
}