How would I split a stream in Apache Storm?

混江龙づ霸主 提交于 2019-11-27 00:54:25

问题


I am not understanding how I would split a stream in Apache Storm. For example, I have bolt A that after some computation has somevalue1, somevalue2, and somevalue3. It wants to send somevalue1 to bolt B, somevalue2 to bolt C, and somevalue1,somevalue2 to bolt D. How would I do this in Storm? What grouping would I use and what would my topology look like? Thank you in advance for your help.


回答1:


You can use different streams if your case needs that, it is not really splitting, but you will have a lot of flexibility, you could use it for content based routing from a bolt for instance:

You declare the stream in the bolt:

@Override
public void declareOutputFields(final OutputFieldsDeclarer outputFieldsDeclarer) {
    outputFieldsDeclarer.declareStream("stream1", new Fields("field1"));
    outputFieldsDeclarer.declareStream("stream2", new Fields("field1"));
}

You emit from the bolt on the chosen stream:

collector.emit("stream1", new Values("field1Value"));

You listen to the correct stream through the topology

builder.setBolt("myBolt1", new MyBolt1()).shuffleGrouping("boltWithStreams", "stream1");
builder.setBolt("myBolt2", new MyBolt2()).shuffleGrouping("boltWithStreams", "stream2");



回答2:


You have two options here: Stream Groups and "Direct Grouping". Depending on your requirements, one of them is going to serves you.

Have a look at WordCountTopology sample project to see whether that is what you are looking for. Otherwise, "Direct Grouping" is going to be a better alternative.

But again, picking a grouping strategy depends on your requirements.



来源:https://stackoverflow.com/questions/19807395/how-would-i-split-a-stream-in-apache-storm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!