Jud*_*ing 5 java topology apache-storm
我改变了类WordCount中WordCountTopology,如下所示:
public static class WordCount extends BaseBasicBolt {
Map<String, Integer> counts = new HashMap<String, Integer>();
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
String word = tuple.getString(0);
Integer count = counts.get(word);
if(count==null) count = 0;
count++;
counts.put(word, count);
OutputStream o;
try {
o = new FileOutputStream("~/abc.txt", true);
o.write(word.getBytes());
o.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
collector.emit(new Values(word, count));
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("word", "count"));
}
}
Run Code Online (Sandbox Code Playgroud)
在其中我将单词写到文件中abc.txt。
当我WordCountTopology在本地模式(使用LocalCluster)中运行时,它工作正常。但是当在分布式模式(使用该StormSubmitter.submitTopology()方法)下运行时,WordCount该类没有写出该单词,abc.txt就好像该execute()方法根本没有运行。谁能给我一些想法?非常感谢!
PS我敢肯定,我的灵气,监事,UI,动物园管理员运行正常,我可以看到任务127.0.0.1:8080。
主要问题是 abc.txt 文件的位置。该文件将在您提交拓扑的系统中创建。因此该文件在其他集群机器中不可用。您可以检查主管日志中是否有文件未找到错误。解决此问题,您需要一些 NFS 配置,通过该配置可以由所有集群计算机共享公共位置。配置 NFS 后,在公共位置创建新文件,以便所有主管都可以使用该文件。
| 归档时间: |
|
| 查看次数: |
2597 次 |
| 最近记录: |