风暴拓扑的螺栓接收重复结果

时间:2014-05-06 10:38:09

标签: java apache-storm

我使用从另一个螺栓接收元组的螺栓(感叹号)并将其写入文件,我得到的问题是我有四次重复的结果,就像我发出一个单词,我发现这个词写了四次。问题可能在哪里?

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) {
    }
}

1 个答案:

答案 0 :(得分:1)

解决方案是在主类中指定1个喷口:

builder.setSpout(“spout”,new RandomSentenceSpout(),1);