everyone.I want to do the job—— one spout emit numbers to blotA,and BlotA emit odd number to Blot_odd , BlotA emit even number to Blot_even. I choose one way to use emit(streamId,tuple)
,but I don't know where to define my streamId?
每个人。我想做这个工作 - 一个喷口发出数字到blotA,BlotA向Blot_odd发出奇数,BlotA向Blot_even发出偶数。我选择一种方法来使用emit(streamId,tuple),但我不知道在哪里定义我的streamId?
In the Blot_odd / Blot_even ,
在Blot_odd / Blot_even中,
declareOutputFields(){declarer.declareStream("streamId", new Fields("fieldName"));}
and in main
of MyTopology.java
以及MyTopology.java的主要内容
main() {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("num", new NumSpout(), 10);
builder.setBolt("judge", new Bolt(), 3).shuffleGrouping("num");
builder.setBolt("odd", new Bolt_odd(), 2).shuffleGrouping("judge");
builder.setBolt("even", new Bolt_even(), 2).shuffleGrouping("judge");
}
but I failed.
但我失败了。
1 个解决方案
#1
You can do like below.
你可以在下面这样做。
in declareOutputFields method of Bolt, fill in the details like this.
在Bolt的declareOutputFields方法中,填写这样的细节。
declarer.declareStream("oddstream", new Fields("fieldName"));
declarer.declareStream("evenstream", new Fields("fieldName"));
And you can declare topology like below.
您可以声明如下的拓扑。
builder.setSpout("num", new NumSpout(), 10);
builder.setBolt("judge", new Bolt(), 3).shuffleGrouping("num");
builder.setBolt("odd", new Bolt_odd(), 2).shuffleGrouping("judge", "oddstream");
builder.setBolt("even", new Bolt_even(), 2).shuffleGrouping("judge", "evenstream");
#1
You can do like below.
你可以在下面这样做。
in declareOutputFields method of Bolt, fill in the details like this.
在Bolt的declareOutputFields方法中,填写这样的细节。
declarer.declareStream("oddstream", new Fields("fieldName"));
declarer.declareStream("evenstream", new Fields("fieldName"));
And you can declare topology like below.
您可以声明如下的拓扑。
builder.setSpout("num", new NumSpout(), 10);
builder.setBolt("judge", new Bolt(), 3).shuffleGrouping("num");
builder.setBolt("odd", new Bolt_odd(), 2).shuffleGrouping("judge", "oddstream");
builder.setBolt("even", new Bolt_even(), 2).shuffleGrouping("judge", "evenstream");