How to send final kafka-streams aggregation result of a time windowed KTable? : <p>What I'd like to do is this:</p>

<ol>
<li>Consume records from a numbers topic (Long's)</li>
<li>Aggregate (count) the values for each 5 sec window</li>
<li>Send the FINAL aggregation result to another topic</li>
</ol>

<p>My code looks like this:</p>

<pre><code>KStream&lt;String, Long&gt; longs = builder.stream(
        Serdes.String(), Serdes.Long(), "longs");

// In one ktable, count by key, on a five second tumbling window.
KTable&lt;Windowed&lt;String&gt;, Long&gt; longCounts = 
        longs.countByKey(TimeWindows.of("longCounts", 5000L));

// Finally, sink to the long-avgs topic.
longCounts.toStream((wk, v) -&gt; wk.key())
        .to("long-counts");
</code></pre>

<p>It looks like everything works as expected, but the aggregations are sent to the destination topic for each incoming record. My question is how can I send only the final aggregation result of each window?</p>
