popular: 1.3.0 - Changed the type-mapping from `word` to `key`
[demos/kafka/wordcount] / src / main / java / de / juplo / kafka / wordcount / popular / PopularStreamProcessor.java
index 9bcf0f7..74aa2c6 100644 (file)
@@ -12,8 +12,6 @@ import org.springframework.kafka.support.serializer.JsonSerde;
 import org.springframework.kafka.support.serializer.JsonSerializer;
 
 import java.time.Duration;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
 import java.util.Map;
 import java.util.Properties;
 import java.util.stream.Collectors;
@@ -22,6 +20,7 @@ import java.util.stream.Collectors;
 @Slf4j
 public class PopularStreamProcessor
 {
+       public static final String TYPE = "POPULAR";
        public static final String KEY_VALUE_STORE_NAME = "popular";
        public static final String WINDOW_STORE_NAME = "popular-windows";
        public static final Duration WINDOW_SIZE = Duration.ofSeconds(30);
@@ -34,14 +33,12 @@ public class PopularStreamProcessor
                        String inputTopic,
                        String outputTopic,
                        Properties properties,
-                       ZoneId zone,
                        WindowBytesStoreSupplier windowBytesStoreSupplier,
                        KeyValueBytesStoreSupplier keyValueBytesStoreSupplier)
        {
                Topology topology = PopularStreamProcessor.buildTopology(
                                inputTopic,
                                outputTopic,
-                               zone,
                                windowBytesStoreSupplier,
                                keyValueBytesStoreSupplier);
 
@@ -51,7 +48,6 @@ public class PopularStreamProcessor
        static Topology buildTopology(
                        String inputTopic,
                        String outputTopic,
-                       ZoneId zone,
                        WindowBytesStoreSupplier windowBytesStoreSupplier,
                        KeyValueBytesStoreSupplier keyValueBytesStoreSupplier)
        {
@@ -74,8 +70,7 @@ public class PopularStreamProcessor
                                .peek((windowedWord, counter) -> log.info("windowed: {} -> {}", windowedWord, counter))
                                .map((windowedWord, counter) -> new KeyValue<>(
                                                WindowedWord.of(
-                                                               ZonedDateTime.ofInstant(windowedWord.window().startTime(), zone),
-                                                               ZonedDateTime.ofInstant(windowedWord.window().endTime(), zone),
+                                                               Long.toString(windowedWord.window().startTime().getEpochSecond()),
                                                                windowedWord.key().getWord()),
                                                WordCounter.of(windowedWord.key().getWord(), counter)))
                                .peek((windowedWord, wordCounter) -> log.info("results: {} -> {}", windowedWord, wordCounter))
@@ -147,11 +142,11 @@ public class PopularStreamProcessor
                return typeMappingsConfig(WindowedWord.class, WordCounter.class);
        }
 
-       public static String typeMappingsConfig(Class wordClass, Class wordCounterClass)
+       public static String typeMappingsConfig(Class keyClass, Class counterClass)
        {
                return Map.of(
-                                               "word", wordClass,
-                                               "counter", wordCounterClass)
+                                               "key", keyClass,
+                                               "counter", counterClass)
                                .entrySet()
                                .stream()
                                .map(entry -> entry.getKey() + ":" + entry.getValue().getName())