[英]Storm : How to pass String Array from one bolt to another?
This is how I am emitting the data 这就是我发送数据的方式
collector.emit("stream", new Values(sessionid,tables));
Where sessionid
and tables
are ArrayList<String>
其中
sessionid
和tables
是ArrayList<String>
I am not sure how the bolt which will receive the data will get it as I didn't find anything to get the value in Tuple. 我不确定接收数据的螺栓将如何获得它,因为我没有找到任何东西来获取元组中的值。
This is how my execute method of receiving bolt will look. 这就是我接收螺栓的执行方法的样子。
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);
}
Alternatively, I am thinking of merging the value of the ArrayList
in a comma separated string and pass it as a string and then split it and save it in ArrayList
in the receiving bolt. 或者,我正在考虑在逗号分隔的字符串中合并
ArrayList
的值并将其作为字符串传递,然后将其拆分并将其保存在接收螺栓的ArrayList
中。
But, is there any clean way to pass ArrayList
to Storm bolts? 但是,有没有什么干净的方法将
ArrayList
传递给Storm螺栓?
You can pass ArrayList
without problems. 您可以毫无问题地传递
ArrayList
。 You just need to use Tuple.getValue(int)
(or Tuple.getValueByField(String)
) and cast to the correct type: 您只需要使用
Tuple.getValue(int)
(或Tuple.getValueByField(String)
)并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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.