我有一个 arrayList,我想在另一个 bolt 中发送和接收它。 因此,正如我在另一篇文章中所建议的那样: 第一个 bolt :
collector.emit(new Values(listI));
下一个 bolt :
public void execute(Tuple tuple) {
ArrayList<Integer> i = (ArrayList<Integer>)tuple.getValue(0);
....
}
但我得到的不是大小为 4 的列表,而是大小为 0 的列表。 有什么想法吗?
最佳答案
不确定 listI 是什么类型(我假设是 ArrayList)。如果是这样,你的第一个 bolt 可能有这个:
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
List<Integer> listI = getSomeListOfIntegers();
collector.emit(new Values(listI));
}
确保您也在 bolt 1 中声明了它:
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("listI"));
}
然后在你的第二个 bolt 中:
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
List<Integer> listOfInts = (List<Integer>)tuple.getValue(0);
}
关于java - 如何在 Storm 中发射和收集数组列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35898575/