【问题标题】:Trigger elements exactly once using Fixed Windowing with Apache Beam使用 Apache Beam 的 Fixed Windowing 仅触发一次元素
【发布时间】:2020-11-22 09:30:33
【问题描述】:

我正在从 Google pub-sub 读取数据并将它们窗口化为 5 分钟的固定窗口。但是 - 数据未正确触发。我尝试了多种组合,似乎没有任何效果。这看起来相当简单 - 但我无法正确处理。

用例 -

  1. 从 pub-sub 读取数据
  2. 将它们窗口化为 5 分钟
  3. 在 5 分钟窗口结束后执行聚合。
  4. AllowedLateness 为 1 天。

尝试:

1.使用AfterWatermark.pastEndOfWindow触发。这根本不会产生任何输出。从订阅中读取了大约 1000 条消息,但窗口没有输出任何消息。

Window.<EventModel>into(
                FixedWindows.of(Duration.standardMinutes(5)))
                .triggering(AfterWatermark.pastEndOfWindow())
                .withAllowedLateness(Duration.standardDays(1), Window.ClosingBehavior.FIRE_ALWAYS)
                .discardingFiredPanes();

2.使用全局窗口:这可以正常工作。但这使用 GlobalWindows - 但我需要实现固定窗口。

Window<EventModel> window = Window.<OrderEvent>
                into(new GlobalWindows())
                .triggering(
                        Repeatedly.forever( 
              AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardMinutes(5))))
                .discardingFiredPanes()
                .withAllowedLateness(Duration.standardDays(1));

我尝试了其他组合使用 - Early Firings 或 Late Firings - 触发一些元素但不适合我的用例 - 我不需要提前或延迟触发 - 只需要每 5 分钟一次的结果。

任何意见都会非常有帮助,我在这方面投入了太多时间,但没有运气。

【问题讨论】:

    标签: java google-cloud-platform apache-beam google-cloud-pubsub windowing


    【解决方案1】:

    发现问题:

    这是 DirectRunner 的错误。由于某种原因 - 直接跑步者没有推进水印,因此没有触发任何事情。

    以下代码正常工作 - 使用 Dataflow Runner - 元素在窗口结束后触发。

    Window<MyModel> window = Window.<MyModel>into(FixedWindows.of(Duration.standardMinutes(10)))
                        .triggering(Repeatedly.forever(AfterWatermark.pastEndOfWindow()))
                        .withAllowedLateness(Duration.standardDays(1))
                        .discardingFiredPanes();
    

    【讨论】:

      猜你喜欢
      • 2018-05-25
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多