簡體   English   中英

如何使用 Apache Beam 中的流輸入 PCollection 請求 Redis 服務器?

[英]How to request Redis server using a streaming input PCollection in Apache Beam?

使用RedisIO ,我正在嘗試將集合查詢到 redis 服務器。

Redis 服務器正常並且只有在批處理管道(無流)時響應良好。

但是,使用這樣的流輸入數據(來自文件):

  PCollection<String> stream = pipeline.apply("ReadMyFile", TextIO.read().from("/home/out/**")
  .watchForNewFiles(Duration.standardSeconds(60), Watch.Growth.<String>never()))   
  .apply("ParseFn", ParDo.of(new ParseFn()))
  .apply("GlobalString", GlobalString.get(Duration.ZERO, Duration.standardSeconds(60)));

然后,應用 redisIO read() 函數:

 PCollection<KV<String, String>> redis = stream.apply(RedisIO.readAll().withEndpoint("127.0.0.1", 6379));

最后,想使用結果集合,所以:

 PCollection<String> result = redis.apply("Compose Final Object", ParDo.of(new DoFn<KV<String, String>, String>() {
    @ProcessElement
    public void processElement(ProcessContext c) {
      System.out.println(c.element().getKey());
      c.output(c.element().getKey());
    }
  }));

據我測試,文件正在根據需要加載和處理。

對於進一步的發展,這是一個錯誤:

https://github.com/apache/beam/pull/10624/commits

https://issues.apache.org/jira/browse/BEAM-9134

它很快就會被修復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM