counter: 1.3.0 - (GREEN) Fixed the typing for the state-store
authorKai Moritz <kai@juplo.de>
Wed, 5 Jun 2024 21:57:32 +0000 (23:57 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 8 Jun 2024 11:33:30 +0000 (13:33 +0200)
src/main/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessor.java

index fd5c5a7..64bd619 100644 (file)
@@ -7,6 +7,7 @@ import org.apache.kafka.streams.kstream.Materialized;
 import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
 import org.apache.kafka.streams.state.QueryableStoreTypes;
 import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
+import org.springframework.kafka.support.serializer.JsonSerde;
 
 import java.util.Properties;
 
@@ -46,7 +47,10 @@ public class CounterStreamProcessor
                source
                                .map((key, word) -> new KeyValue<>(word, word))
                                .groupByKey()
-                               .count(Materialized.as(storeSupplier))
+                               .count(
+                                               Materialized
+                                                               .<Word, Long>as(storeSupplier)
+                                                               .withKeySerde(new JsonSerde<>().copyWithType(Word.class).forKeys()))
                                .toStream()
                                .map((word, counter) -> new KeyValue<>(word, WordCounter.of(word, counter)))
                                .to(outputTopic);