import org.apache.kafka.streams.kstream.TimeWindows
import scala.concurrent.duration._
val everyMinute = TimeWindows.of(1.minute.toMillis)
import org.apache.kafka.streams.scala.StreamsBuilder
import org.apache.kafka.streams.scala._
import ImplicitConversions._
import Serdes._
val builder = new StreamsBuilder
val windowedKStream = builder
.stream[String, String]("events")
.groupByKey
.windowedBy(everyMinute)
scala> :type windowedKStream
org.apache.kafka.streams.scala.kstream.TimeWindowedKStream[String,String]
// Print out counts over 1-minute time windows to stdout
import org.apache.kafka.streams.kstream.Printed
import org.apache.kafka.streams.kstream.Windowed
val stdout = Printed
.toSysOut[Windowed[String], Long]
.withLabel("[time-windows]")
windowedKStream
.count
.toStream
.print(stdout)
// Use println(builder.build.describe) to see the whole topology
TimeWindowedKStream — Time-Windowed Streaming Aggregations
TimeWindowedKStream
is the abstraction of a windowed record stream that allows Kafka Streams developers for aggregate, count, reduce aggregations.
TimeWindowedKStream
is the result of KGroupedStream.windowedBy stream operator with a TimeWindows window specification.
Tip
|
Use Scala API for Kafka Streams to make your Kafka Streams development more pleasant if Scala is your programming language. |
Method | Description |
---|---|
|
Creates a KTable with a given |
|
Creates a KTable with a given Materialized (view of a WindowStore) |
|
Combining record stream (by a grouped key) Creates a KTable with a given |
Note
|
TimeWindowedKStreamImpl is the one and only known implementation of the TimeWindowedKStream Contract in Kafka Streams 2.3.0. |