zoukankan      html  css  js  c++  java
  • [QA翻译]如何在Storm里拆分stream流?

    原文:http://stackoverflow.com/questions/19807395/how-would-i-split-a-stream-in-apache-storm

    问题:
    我现在不清楚如何在storm里拆分stream流。比如,我的Bolt A经过计算有somevalue1, somevalue2, and somevalue3等值。我希望发送somevalue1到bolt B,somevalue2到bolt C,somevalue1,somevalue2到bolt D。在strom里我应当怎么做?我应当在我的topology里使用何种grouping?提前先感谢您的帮助。

    --------------------------------------------

    回答:

    你的情况可以使用多个stream流来应对,这并不是真正意义的拆分,但你将获得很多灵活性,你可以把它视为基于bolt实例内容的路由。

    你需要在boltA中声明stream:

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

    在boltA里选择性的提交stream流:

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

    在拓扑定义时设置监听接收正确的stream流

    builder.setBolt("boltB", new MyBolt1()).shuffleGrouping("boltA", "stream1");
    builder.setBolt("boltC", new MyBolt2()).shuffleGrouping("boltA", "stream2");
    builder.setBolt("boltD", new MyBolt3()).shuffleGrouping("boltA", "stream1").shuffleGrouping("boltA", "stream2");
  • 相关阅读:
    HackerRank
    HackerRank
    LeetCode "Kth Smallest Element in a BST"
    HackerRank
    HackerRank
    LeetCode "Roman to Integer"
    LeetCode "Integer to Roman"
    LeetCode "Majority Element II"
    HackerRank
    HackerRank
  • 原文地址:https://www.cnblogs.com/dyfh/p/4048881.html
Copyright © 2011-2022 走看看