Google cloud dataflow 如何在不在管道内运行的情况下使用Apache beam连接器

Google cloud dataflow 如何在不在管道内运行的情况下使用Apache beam连接器,google-cloud-dataflow,apache-beam,google-cloud-pubsub,Google Cloud Dataflow,Apache Beam,Google Cloud Pubsub,我们正在kubernetes吊舱中运行我们的程序,该吊舱正在收听pubsub消息。它根据消息数据类型启动数据流作业。一旦作业执行完成,我们再次向另一个系统发送pubsub消息 管道以批处理模式启动,从地面军事系统读取,并在处理后写入地面军事系统 Pipeline pipeline = Pipeline.create(options); PCollection<String> read = pipeline .apply("Read from GCS",

我们正在kubernetes吊舱中运行我们的程序,该吊舱正在收听pubsub消息。它根据消息数据类型启动数据流作业。一旦作业执行完成,我们再次向另一个系统发送pubsub消息

管道以批处理模式启动,从地面军事系统读取,并在处理后写入地面军事系统

Pipeline pipeline = Pipeline.create(options);
PCollection<String> read = pipeline
                .apply("Read from GCS",
                        TextIO.read().from("GCS_PATH").withCompression(Compression.GZIP));

//process 
// write to GCS
....
PipelineResult result = pipeline.run();
result.waitUntilFinish();

# send job completed message to Pubsub to other component
....
....

为了解决这个用例,您可以使用Wait API。详情见

PCollection firstWriteResults=data.apply(ParDo.of(…写入第一个数据库…);
data.apply(Wait.on(firstWriteResults))
//此中间PCollection的窗口将不早于
//firstWriteResults的相应窗口将关闭。
.apply(ParDo.of(…写入第二个数据库…);

为什么要将输出写入GCS,直接将输出写入pubsub有什么问题。我们将处理后的数据写入datalake。一旦批处理作业完成,我们将使用pubsub通知其他组件进行进一步分析。所以pubsub只用于发送关于数据流作业的开始和结束信息。在写入之后,我不能使用apply。还要检查答案的语法。
PubsubIO.writeMessages().to("topicName");
 PCollection<Void> firstWriteResults = data.apply(ParDo.of(...write to first database...));
 data.apply(Wait.on(firstWriteResults))
     // Windows of this intermediate PCollection will be processed no earlier than when
     // the respective window of firstWriteResults closes.
     .apply(ParDo.of(...write to second database...));