简体   繁体   中英

Apache Storm (Java): Bolt not receiving tuple from other Bolt

I'm working with Apache Storm with this topology:

 TopologyBuilder builder = new TopologyBuilder();   
    builder.setSpout("socketspout", new SocketSpout(IP_HOST,PORT));
    builder.setBolt("filterone", new FilterOne()).shuffleGrouping("socketspout");
    builder.setBolt("filtertwo", new FilterTwo()).shuffleGrouping("filterone");

The methods of the first bolt are (FilteOne), this class extends BaseRichBolt:

public void declareOutputFields(OutputFieldsDeclarer declarer) {
    declarer.declare(new Fields("ID1","signal1"));
}

 public void execute(Tuple input) {
    int sig;
    try {
        sig=input.getInteger(1)*2;
        System.out.println("Filter one.."+Integer.toString(sig));
        collector.emit("ack1", new Values(input.getString(0), sig));
        collector.ack(input);
    } catch (Exception e) {
        collector.fail(input);
    }
}

The methods of the second bolt are (FilteTwo), this class extends BaseRichBolt too:

public void declareOutputFields(OutputFieldsDeclarer declarer) {
}

 public void execute(Tuple input) {
    int sig;
    try {
        sig=input.getInteger(1)+1;
        System.out.println("Filter two.."+Integer.toString(sig));
        collector.ack(input);
    } catch (Exception e) {
        collector.fail(input);
    }
}

When execute the program mode localcluster I can see the first bolt emit the tuple but the second never receive the tuple......

在此处输入图片说明

The problem was solved modifying the filter one code from collector.emit("ack1", new Values(input.getString(0), sig)); to collector.emit( new Values(input.getString(0), sig));

The method emit's collector could set up as like:

collector.emit(input, new Values(input.getString(0), sig));

don't forget set the field name for this value, in method declareOutputFields:

public void declareOutputFields(OutputFieldsDeclarer declarer) {
        declarer.declare(new Fields("myValue"));
    }

Then, in the second bolt, try to get the value using "myValue" field:

sig = input.getValueByField("myValue").getInteger(1)+1;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM