[英]Apache Beam Not Saving Unbounded Data To Text File
我創建了一個管道,使用 Apache Beam 和 Java 將 Google Cloud Pubsub 消息保存到文本文件中。 每當我使用--runner=DataflowRunner
在 Google Dataflow 中運行管道時,消息都會正確保存。
但是,當我使用--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();
}
我做錯了什么? 是否可以在本地運行此管道?
在測試管道時,我遇到了與您相同的問題。 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)
)
)
)
這樣文件就按原樣寫入。 希望這會幫助某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.