EmitStrategy configures when a Kafka Streams windowed aggregation forwards results. Windowed operations can emit updates while a window remains open or wait for the window to close and emit one final result. section 9.3 section 9.7
Choose the emission behavior on the windowed operation:
- Use EmitStrategy.onWindowClose() to emit only when the window closes, producing a single final result for that interval. section 9.3
- Use EmitStrategy.onWindowUpdate(), or omit the policy, to retain the default behavior of emitting updates as windowed results change. section 9.3
- Apply EmitStrategy to windowed aggregations; non-windowed infinite streams do not have a natural final result. section 9.3
Emit one result when a tumbling window closes
iotHeatSensorStream.groupByKey() .windowedBy(TimeWindows.ofSizeWithNoGrace( Duration.ofMinutes(1))) .emitStrategy(EmitStrategy.onWindowClose()) .aggregate(...) The strategy follows windowedBy and precedes the aggregation, changing the output from intermediate updates to a final result at window closure. section 9.3
Figure 9.29 Only a single result is emitted when a window closes.
Compare the output shape visually: a closing-window strategy emits only one result when the window closes. section 9.3
