counter: 1.1.5 - Fixed a bug in the integration-test `CounterApplicationIT`
[demos/kafka/wordcount] / src / main / java / de / juplo / kafka / wordcount / counter / CounterApplication.java
index 1ee65ca..20cb4d2 100644 (file)
@@ -5,6 +5,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.clients.consumer.ConsumerConfig;
 import org.apache.kafka.common.serialization.Serdes;
 import org.apache.kafka.streams.StreamsConfig;
+import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
+import org.apache.kafka.streams.state.Stores;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -25,6 +27,7 @@ public class CounterApplication
        @Bean(initMethod = "start", destroyMethod = "stop")
        public CounterStreamProcessor streamProcessor(
                        CounterApplicationProperties properties,
+                       KeyValueBytesStoreSupplier storeSupplier,
                        ObjectMapper objectMapper,
                        ConfigurableApplicationContext context)
        {
@@ -34,12 +37,18 @@ public class CounterApplication
                propertyMap.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, properties.getBootstrapServer());
                propertyMap.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.StringSerde.class.getName());
                propertyMap.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.StringSerde.class.getName());
+               propertyMap.put(StreamsConfig.STATE_DIR_CONFIG, "target");
+               if (properties.getCommitInterval() != null)
+                       propertyMap.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, properties.getCommitInterval());
+               if (properties.getCacheMaxBytes() != null)
+                       propertyMap.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, properties.getCacheMaxBytes());
                propertyMap.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
 
                CounterStreamProcessor streamProcessor = new CounterStreamProcessor(
                                properties.getInputTopic(),
                                properties.getOutputTopic(),
                                propertyMap,
+                               storeSupplier,
                                objectMapper);
 
                streamProcessor.streams.setUncaughtExceptionHandler((Throwable e) ->
@@ -57,6 +66,12 @@ public class CounterApplication
                return streamProcessor;
        }
 
+       @Bean
+       public KeyValueBytesStoreSupplier storeSupplier()
+       {
+               return Stores.persistentKeyValueStore("counter");
+       }
+
        public static void main(String[] args)
        {
                SpringApplication.run(CounterApplication.class, args);