I need to emit an event for the first time the aggregated value reaches 100, this is what it looks right now
StreamsBuilder sb = new StreamsBuilder();
KTable<Integer, Integer> example =
sb.stream(inputs, Consumed.with(Serdes.Integer(), Serdes.Integer()))
.groupByKey()
.aggregate(
() -> 0,
(key, value, currentValue) -> {
var newValue = currentValue + value;
if (currentValue != 100 && newValue == 100) {
PublishEvent(key, "REACH 100!");
}
return newValue;
},
Materialized.with(Serdes.Integer(), Serdes.Integer())
);
Is it good practice to do PublishEvent() in the aggregate function because it may create a side effect during the aggregation? if it is, I am not sure how to write this PublishEvent() function? if not, how could I emit for the first time the aggregated value reaches 100?