我有兩個螺栓類BoltX
和BoltY
。 BoltY
從BoltX
接收元組。 BoltX
聲明輸出具有多個字段,每個元組包含4個字符串:風暴中的多個字段分組
class BoltX implements IBasicBolt {
...
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("A","B","C","D"));
}
}
在BoltY
:
class BoltX implements IBasicBolt {
boolean hasReceive = false;
String A = null;
String B = null;
...
public void execute(Tuple input, BasicOutputCollector collector) {
if (!hasReceive) {
hasReceive = true;
A = input.getString(0);
B = input.getString(1);
}
if (!input.getString(0).equals(A) || !input.getString(1).equals(B)) {
LOG.error("group error");
return;
}
...
}
...
}
在拓撲:
...
builder.setBolt("x", new BoltX(), 3);
builder.setBolt("y", new Bolty(), 3).fieldsGrouping("x", new Fields("A", "B"));
...
我認爲,從X與同場的輸出「A」和「B」將執行BoltY
的相同任務。
但是,拓撲結構的日誌顯示了很多「組錯誤」。
那麼如何將具有相同字段「A」和「B」的輸出分組到同一個任務BoltY
?
字段分組在這裏正確解釋:http://nrecursions.blogspot.in/2016/09/understanding-fields-grouping-in-apache.html – Anon