apache-kafka-streams

More than one tumbling window


I am trying to understand whether I can achieve the following behavior with Kafka Streams, with grace configuration or in any other way:


Solution

  • Yes, you would use TimeWindows.ofSizeAndGrace(Duration.ofMinutes(1L), Duration.ofMinutes(2)) to specify the window.

    Time is taken from a field in the message, lets call it messageTime field

    You can write a custom TimestampeExtractor to use messageTime as timestamp, and pass it via StreamsConfig.

    If you only want to get a single final result when a window is closed, you can use either suppress() (on the KTable result) or windowedBy(...).emitStrategy(...).aggregate(...). (Note that window are only closed when "stream time" advances beyond their close time, so if input data stops flowing, time stops advancing and windows are kept open.)