Apache Storm: split a stream to different bolts

569 views Asked by At

I making storm topology and I'm dealing with strings from this format: "x-x-x-x" where x is some digit. I want the strings stream to be split between 4 bolts equaly.

The problem is that for the following code, all the bolts get all the tuples, instead of send eack tuple to exactly one bolt:

builder.setSpout("digits-spout", new ReaderSpout());
builder.setBolt("level-1", new SomeBolt(1)).shuffleGrouping("digits-spout");
builder.setBolt("level-2", new SomeBolt(2)).shuffleGrouping("digits-spout");
builder.setBolt("level-3", new SomeBolt(3)).shuffleGrouping("digits-spout");
builder.setBolt("level-4", new SomeBolt(4)).shuffleGrouping("digits-spout");

as you can see i use same bolt but different consturctor. Thanks!

2

There are 2 answers

0
Harsh Kumar On

If you want the bolts to have different processing logic, you can just add 4 tasks of the same bolt. In this case, you will receive messages randomly between the bolt instances. You can check for the string value within that bolt and take appropriate execution path. You will avoid separate codebase for 4 bolts.

Alternatively, if you want to have separate bolt code for the strings, go for above suggestion by zackeriya.

0
cekeriya On

According to what I understand from your question, I may offer an extra bolt for your problem like following example:

builder.setSpout("digits-spout", new ReaderSpout());

builder.setBolt("stringSplitterBoltName", new 
StringSplitterBolt(1)).shuffleGrouping("digits-spout");

builder.setBolt("level-1", new 
SomeBolt(1)).shuffleGrouping("stringSplitterBoltName");

builder.setBolt("level-2", new 
SomeBolt(2)).shuffleGrouping("stringSplitterBoltName");

builder.setBolt("level-3", new 
SomeBolt(3)).shuffleGrouping("stringSplitterBoltName");

builder.setBolt("level-4", new 
SomeBolt(4)).shuffleGrouping("stringSplitterBoltName");