liveBook · Manning

EmitStrategy

As explained in Kafka Streams in Action, Second Edition

EmitStrategy is a Kafka Streams configuration API that specifies when results from a windowed operation are emitted.

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.
figure

Compare the output shape visually: a closing-window strategy emits only one result when the window closes. section 9.3

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains placement, default behavior, and closing-window configuration, while deferring detailed stream-time mechanics.
Examples
Demonstrates a one-minute IoT heat-sensor tumbling aggregation configured with onWindowClose().
What it assumes
Assumes familiarity with KStream groupByKey(), windowedBy(), and aggregation, while treating final-result emission as the new decision.
What you can do after
Operate/configure Kafka Streams windowed aggregations to emit updates by default or final results when windows close.
How it connects
Connects windowed aggregations with tumbling windows, stream time, timestamps, and suppression.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.