KStream<String, dummy> demoZone = builder.stream(fromTopic, Consumed.with(Serializer.getSerde(String.class), Serializer.getSerde(dummy.class)));
我想在1分钟的demoZone上应用窗口,并找到该1分钟数据的平均值
答案 0 :(得分:1)
您可以使用如下所示的TimeWindow:
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);
您可以在此处找到有关Windowing的更多详细信息:
https://docs.confluent.io/current/streams/developer-guide/dsl-api.html#windowing