我有一个编写如下的kstreams应用。背后的逻辑是仅将每个键的最早记录流式传输到ktable。我想在指定的时间(60秒)内禁止对键的ktable更新。但是,提及抑制配置似乎无济于事。
KStream<String, JsonNode> messagesStream = builder.stream("testtopic",
Consumed.with(stringSerde, jsonSerde));
KTable<String, JsonNode> aggregatedMessageStream = messagesStream
.groupBy((key, value) -> value.get("key-part1").toString()+"-"+value.get("key-part2").toString())
.reduce(
new Reducer<JsonNode>() {
@Override
public JsonNode apply(JsonNode value1, JsonNode value2) {
return getEarliest(value1, value2);
}
}).suppress(Suppressed.untilTimeLimit(Duration.ofSeconds(60), Suppressed.BufferConfig.maxBytes(10000000L).emitEarlyWhenFull()));
aggregatedMessageStream.toStream().to("testtopicAgg", Produced.with(stringSerde, jsonSerde));
例如,同时针对“ testtopic”主题产生了以下4条记录。
{"key-part1":"123","key-part2":"456","timestampField":"2019-09-25T02:32:21.0Z","user":"user1"}
{"key-part1":"123","key-part2":"456","timestampField":"2019-09-25T03:32:21.0Z","user":"user2"}
{"key-part1":"123","key-part2":"456","timestampField":"2019-09-25T04:32:21.0Z","user":"user3"}
{"key-part1":"123","key-part2":"456","timestampField":"2019-09-25T05:32:21.0Z","user":"user4"}
大约10秒钟后,我在主题“ testtopicAgg”中看到1条记录的输出,按照逻辑是准确的。
{"key-part1":"123", "key-part2":"456","timestampField":"2019-09-25T02:32:21.0Z","user":"user1"}
但是我想理想地将此记录的生成延迟60s到“ testtopicAgg”。因此,我尝试使用抑制方法。任何信息表示赞赏。可能我对其中一些概念有错误的理解,因为我不是kafka流媒体的新手。