Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Apache Beam未将无界数据保存到文本文件_Java_Google Cloud Dataflow_Apache Beam - Fatal编程技术网

Java Apache Beam未将无界数据保存到文本文件

Java Apache Beam未将无界数据保存到文本文件,java,google-cloud-dataflow,apache-beam,Java,Google Cloud Dataflow,Apache Beam,我已经创建了一个管道,使用ApacheBeam和Java将Google Cloud Pubsub消息保存到文本文件中。 每当我使用--runner=DataflowRunner在Google数据流中运行管道时,消息都会正确保存 但是,当我使用--runner=DirerctRunner运行同一管道时,不会保存消息 我可以通过管道观看事件,但什么也没发生 管道的代码如下所示: public static void main(String[] args) { ExerciseOptions

我已经创建了一个管道,使用ApacheBeam和Java将Google Cloud Pubsub消息保存到文本文件中。 每当我使用
--runner=DataflowRunner
在Google数据流中运行管道时,消息都会正确保存

但是,当我使用
--runner=DirerctRunner
运行同一管道时,不会保存消息

我可以通过管道观看事件,但什么也没发生

管道的代码如下所示:

public static void main(String[] args) {
    ExerciseOptions options = PipelineOptionsFactory.fromArgs(args).withValidation().as(ExerciseOptions.class);

    Pipeline pipeline = Pipeline.create(options);

    pipeline
      .apply("Read Messages from Pubsub",
        PubsubIO
          .readStrings()
          .fromTopic(options.getTopicName()))

      .apply("Set event timestamp", ParDo.of(new DoFn<String, String>() {
        @ProcessElement
        public void processElement(ProcessContext context) {
          context.outputWithTimestamp(context.element(), Instant.now());
        }
      }))

      .apply("Windowing", Window.into(FixedWindows.of(Duration.standardMinutes(5))))

      .apply("Write to File",
        TextIO
          .write()
          .withWindowedWrites()
          .withNumShards(1)
          .to(options.getOutputPrefix()));

    pipeline.run();
  }
publicstaticvoidmain(字符串[]args){
ExerciseOptions=PipelineOptionsFactory.fromArgs(args).withValidation().as(ExerciseOptions.class);
Pipeline=Pipeline.create(选项);
管道
.apply(“从Pubsub读取消息”,
PubsubIO
.readStrings()
.fromTopic(options.getTopicName())
.apply(“设置事件时间戳”,ParDo.of(new DoFn()){
@过程元素
public void processElement(ProcessContext上下文){
outputWithTimestamp(context.element(),Instant.now());
}
}))
.apply(“Windowing”,Window.into(fixed windows.of(Duration.standardMinutes(5)))
.apply(“写入文件”,
TextIO
.write()
.withWindowedWrites()
.与努姆沙兹(1)
.to(options.getOutputPrefix());
pipeline.run();
}

我做错了什么?是否可以在本地运行此管道?

在测试管道时,我遇到了与您相同的问题。
PubSubIO
无法正确使用
DirectRunner
TextIO

我找到了一些解决触发问题的方法

.apply(
                    "2 minutes window",
                    Window
                            .configure()
                            .triggering(
                                    Repeatedly.forever(
                                            AfterFirst.of(
                                                AfterPane.elementCountAtLeast(10),
                                                AfterProcessingTime
                                                        .pastFirstElementInPane()
                                                        .plusDelayOf(Duration.standardMinutes(2))
                                            )
                                    )
                            )
                            .into(
                                FixedWindows.of(
                                        Duration.standardMinutes(2)
                                )
                            )
            )

这样,文件就可以按应有的方式编写。希望这能对其他人有所帮助。

这看起来像DirectRunner中的一个bug,我提交了文件,有人能够解决这个问题吗?可能有什么解决办法吗?哇……在经历了几个小时的挫折之后,我终于找到了解决办法!谢谢