【问题标题】:Storm : How to pass String Array from one bolt to another?Storm:如何将字符串数组从一个螺栓传递到另一个螺栓?
【发布时间】:2019-06-10 18:51:57
【问题描述】:

这就是我发送数据的方式

collector.emit("stream", new Values(sessionid,tables));

其中sessionidtablesArrayList<String>

我不确定将接收数据的螺栓如何获取数据,因为我没有找到任何东西来获取元组中的值。

这就是我接收螺栓的执行方法的样子。

public void execute(Tuple input, BasicOutputCollector collector) {
     ArrayList<String> keyspace = input./*What to add here*/(0);
     ArrayList<String> table = input./*What to add here*/(1);    
}

或者,我正在考虑将ArrayList 的值合并到逗号分隔的字符串中,并将其作为字符串传递,然后将其拆分并保存在接收螺栓中的ArrayList 中。

但是,有没有什么干净的方法可以将ArrayList 传递给 Storm bolts?

【问题讨论】:

    标签: java arraylist apache-storm


    【解决方案1】:

    您可以毫无问题地通过ArrayList。您只需要使用Tuple.getValue(int)(或Tuple.getValueByField(String))并转换为正确的类型:

    public void execute(Tuple input, BasicOutputCollector collector) {
        ArrayList<String> keyspace = (ArrayList<String>)input.getValue(0);
        ArrayList<String> table = (ArrayList<String>)input.getValue(1);
    }
    

    【讨论】:

      猜你喜欢
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 2019-07-26
      • 1970-01-01
      相关资源
      最近更新 更多