Prince
Prince

Reputation: 3

how to apply window with KStreams {use case with java}

KStream<String, dummy> demoZone = builder.stream(fromTopic, Consumed.with(Serializer.getSerde(String.class), Serializer.getSerde(dummy.class)));

I want to apply window on demoZone of 1 minutes and find average of that 1 min data

Upvotes: 0

Views: 128

Answers (1)

Nishu Tayal
Nishu Tayal

Reputation: 20820

You can use TimeWindow as given below :

KTable<Windowed<String>, Long> averageCount = demoZone
        .groupByKey(Serialized.with(Serdes.String(), dummySerde()))
        .windowedBy(TimeWindows.of(TimeUnit.MINUTES.toMillis(5).advanceBy(TimeUnit.MINUTES.toMillis(1))))
        .reduce(// Your aggregate logic here);

You can find more details about Windowing here :
https://docs.confluent.io/current/streams/developer-guide/dsl-api.html#windowing

Upvotes: 1

Related Questions