Different tuples sent from 1 nozzle to another bolt in Apache Storm

Can I send different tuples from 1 nose to another bolt in Apache Storm? For example, I had Spout A, which needs to send Tuple B to Bolt C and Tuple D to Bolt E. How to implement it using spout in Java? I mean how to write code.

OutputCollector.emit(new Values(B, C))?
+4
source share
1 answer

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()
+7
source

Source: https://habr.com/ru/post/1589322/


All Articles