To emit tuples for different bolts from the same Spout, you can use named streams as follows:
Spout
@Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
outputFieldsDeclarer.declareStream("streamA", new Fields("A"));
outputFieldsDeclarer.declareStream("streamB", new Fields("B"));
}
@Override
public void nextTuple() {
outputCollector.emit("streamA", new Values("A"));
outputCollector.emit("streamB", new Values("B"));
}
Then each bolt is attached to a specific thread:
builder.setBolt("MyBoltA", new BoltA()).shuffleGrouping("MySpout", "streamA");
builder.setBolt("MyBoltB", new BoltB()).shuffleGrouping("MySpout", "streamB");
Finally, if a bolt subscribes to multiple threads, you can use the following method to find out which thread the tuple was emitted from:
tuple.getSourceStreamId()
source
share