我使用Google Cloud PubSub和Dataflow来处理我的数据。我想检测我的日常流程何时完成,换句话说,当窗口会话完成/达到间隔持续时间时。对于这种情况,是否有一个触发器可以触发?如果没有,是否有我可以使用的解决方法?
Pipeline p = Pipeline.create(options);
p.apply("ReadPubSubMessage", PubsubIO.readMessages().fromSubscription("projects/project-id/subscriptions/my-sub"))
.apply("ApplyTimestamps", WithTimestamps.of((PubsubMessage pubSub) -> new Instant(System.currentTimeMillis())))
.apply("SessionWindowing", Window.<PubsubMessage>into(Sessions.withGapDuration(Duration.standardMinutes(10)))
.triggering(?)
.withAllowedLateness(Duration.standardSeconds(30))
.discardingFiredPanes())
.apply(new CountWords())
抱歉,如果我错过了文档中明显的东西。
如果我正确理解您的情况,则当达到间隔持续时间(根据会话定义(时,您的窗口结束。因此,您可以使用默认触发器,因为您有边界窗口,因此它只会触发一次。这有意义吗?
在这里,您可以找到 DefaultTrigger 官方文档。
是的,您可以使用 DefaultTrigger.of(( 触发器,我在下面放了一个示例代码。 请注意,它不适用于DirectRunner,但可以在Google Dataflow中使用。
PCollection<KV<String, FormMessageMeta>> formMetaSessionWindowCollection = formMessageMetaKvCollection.apply(
"Session-Window",
Window.<KV<String, FormMessageMeta>>into(
Sessions.withGapDuration(Duration.standardMinutes(40)))
.triggering(DefaultTrigger.of())
.withAllowedLateness(Duration.ZERO).accumulatingFiredPanes());
会话窗口只能应用于 KV。