1.发送的tuple需要携带msgId
collector.emit(new Values(line),index);
2.bolt中需要对tuple进行确认(ack() | fail())
public void execute(Tuple tuple) {
String line = tuple.getString(0);
System.out.println(this + " : " + line);
if(new Random().nextBoolean()){
//确认
collector.ack(tuple);
}
else{
//失败
collector.fail(tuple);
}
}
3.实现spout的ack()和fail()方法,(回调)
public void ack(Object msgId) {
System.out.println(this + " : ack() : " + msgId);
}
public void fail(Object msgId) {
System.out.println(this + " : fail() : " + msgId);
}