我想知道是否给出了KStream,可以根据消息组设置不同的时间窗口,例如,对于groupBy“A”5秒,对于groupBy“B”10秒......
KStream<String, Msg> stream = builder.stream(stringSerde, msgSerde, input);
stream.groupBy((key, msg) -> msg.getPool())
.aggregate(init, agg, TimeWindows.of(wndLength).advanceBy(wndLength), msgSerde)
...
答案 0 :(得分:4)
我们想到的最简单的方法是在.filter()
/ .branch()
之前.groupBy()
或.aggregate()
,例如:
KStream<String, Msg> stream = builder.stream(stringSerde, msgSerde, input);
stream.filter((key, msg) -> msg.getPool().equals("A"))
.groupBy((key, msg) -> msg.getPool())
.aggregate(init, agg, TimeWindows.of(wndLength).advanceBy(wndLength), msgSerde)
...