I did not get the point of setting up two different channels.Can you explain with sample code snippet . Thank you
*Best regards,* *K.Sai Dilip Reddy,* *Software Engineer - Hadoop Trainee,2-39, Old SBI Road, Sri Nagar Colony, Gannavaram - 521101.* *www.aadhya-analytics.com <http://www.aadhya-analytics.com/>.* *[image: Inline image 1]* On Fri, Mar 4, 2016 at 9:45 PM, Aaron.Dossett <[email protected]> wrote: > Since you are declaring that you emit two values you need to emit two > values any time you call emit. If you want to emit two totally different > things at different times (ids and nms) you should set up the bolt to emit > on two different channels. You should also only “ack” your tuple once, at > the end of all your processing. > > From: Sai Dilip Reddy Kiralam <[email protected]> > Reply-To: "[email protected]" <[email protected]> > Date: Tuesday, March 1, 2016 at 6:16 AM > To: "[email protected]" <[email protected]> > Subject: How to emit the values in a for-each loop > > I'm having the a string values which are appended so i used the for each > loop and sliptted them and emit them with in the for each loop.if I'm > getting id string v="1,2,3"; > I'm using for each and emitting the id in for loop itself. > next when I Tried to emit the value of other string which is a appended > one and declaring it as field.I getting the error saying > > java.lang.IllegalArgumentException: Tuple created with wrong number of > fields. Expected 2 fields but got 1 fields at > backtype.storm.tuple.TupleImpl.<init>(TupleImpl.java:58) at > backtype.storm.daemon.executor$fn__5694$fn__5707$bolt_emit__5736.invoke(executor.clj:739) > at > backtype.storm.daemon.executor$fn__5694$fn$reify__5742.emit(executor.clj:763) > at backtype.storm.task.OutputCollector.emit(OutputCollector.java:203) at > backtype.storm.task.OutputCollector.emit(OutputCollector.java:63) at > backtype.storm.task.OutputCollector.emit(OutputCollector.java:101) at > test.bolts.TInserts.execute(TInsert.java:264) > > > > Here is my bolt code. > > public void execute(Tuple tuple) { > try {String screenname=tuple.getStringByField("s_name"); > String mentionname=tuple.getStringByField("n_name"); > String mentionid=tuple.getStringByField("n_id"); > > if(mentionid != null && !mentionid.isEmpty()){ > for(String id:mentionid.split(",")){ > id = id.trim(); > this.collector.emit(new Values(id)); > this.collector.ack(tuple); > }//for close > }//if condtion for id > if(mentionname != null && !mentionname.isEmpty()){ > for(String mns:mentionname.split(",")){ > mns = mns.trim(); > this.collector.emit(new > Values(mns));this.collector.ack(tuple); > }//for close > }//if condtion for mentionname > > } //if close > } > catch (Exception e) { > this.collector.reportError(e); > this.collector.fail(tuple); > } > } > > @Override > public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) > {// outputFieldsDeclarer.declare(new Fields("id"));//doesn't throw any > exception if i emit only id(1st for) > outputFieldsDeclarer.declare(new Fields("id","mns"));//thows exception }} > > please give the suggestion that I need to change in the bolt code. >
