如何在Apache Storm中拆分流? [英] How would I split a stream in Apache Storm?

查看:70
本文介绍了如何在Apache Storm中拆分流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不了解如何在Apache Storm中拆分流.例如,我有一个螺栓A,经过一些计算后它具有somevalue1,somevalue2和somevalue3.它想向螺栓B发送somevalue1,向螺栓C发送somevalue2,向螺栓D发送somevalue1,somevalue2.在Storm中如何做到这一点?我将使用什么分组,拓扑将是什么样?预先感谢您的帮助.

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.

推荐答案

如果您的案例需要,您可以使用不同的流,它并不是真正的拆分,但是您将具有很大的灵活性,您可以将其用于基于内容的例如,从螺栓布线:

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:

您在螺栓中声明流:

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

这篇关于如何在Apache Storm中拆分流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆