简体   繁体   中英

Duplicated result on bolt reception of storm topology

I'm using a bolt that receives tuples from another bolt (exclamation bolt ) and writes it on a file , the problem I got is that I have duplicated results four times , like when I emit a word , I found the word Written four times . where's the problem possibly could be ?

public class PrinterBolty extends BaseBasicBolt {

    @Override
    public void execute(Tuple tuple, BasicOutputCollector collector) {

        try {
            BufferedWriter output;
            output = new BufferedWriter(new FileWriter("/root/src/storm-starter/hh.txt", true));
            output.newLine();
            output.append(tuple.getString(0));
            output.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer ofd) {
    }
}

The solution was to specify 1 spout in the main class :

builder.setSpout("spout", new RandomSentenceSpout(), 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