【问题标题】:read file reference storm from hdfs从 hdfs 读取文件参考风暴
【发布时间】:2015-04-08 16:40:59
【问题描述】:

您好,我想问一些事情。我已经开始了解apachestorm。是否可以在 hdfs 中暴读取数据文件??

示例:我在 hdfs 上的目录 /user/hadoop 中有一个数据 txt 文件。是否有可能风暴读取该文件。??谢谢之前

因为当我尝试运行风暴时,如果文件不存在,我会收到一条错误消息。当我尝试通过从本地存储读取文件来运行它时,它是成功的

 >>> Starting to create Topology ...
---> Read Class: FileReaderSpout , 1387957892009
---> Read Class: Split , 1387958291266
---> Read Class: Identity , 247_Identity_1387957902310_1
---> Read Class: SubString , 1387964607853
---> Read Class: Trim , 1387962789262
---> Read Class: SwitchCase , 1387962333010
---> Read Class: Reference , 1387969791518
File /reff/test.txt .. not exists ..

【问题讨论】:

    标签: hadoop hdfs bigdata apache-storm


    【解决方案1】:

    当然!以下是如何从 HDFS 读取文件的示例:

    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    
    // ...stuff...
    
    FileSystem fs = FileSystem.get(URI.create("hdfs://prodserver"), new Configuration());
    String hdfspath = "/apps/storm/conf/config.json";
    Path path = new Path();
    if (fs.exists(path)) {
       InputStreamReader reader = new InputStreamReader(fs.open(path));
       // do stuff with the reader
    } else {
       LOG.info("Does not exist {}", hdfspath);
    }
    

    这不使用任何特定于风暴的东西,只使用 Hadoop API (hadoop-common.jar)。

    你得到的错误看起来是因为你的文件路径不正确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多