How would I split a stream in Apache Storm?

后端 未结 2 1910
我在风中等你
我在风中等你 2020-12-08 07:29

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 wa

2条回答
  •  孤街浪徒
    2020-12-08 08:05

    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");
    

提交回复
热议问题