Tests aus gemerged springified-consumer--serialization -> deserialization
[demos/kafka/training] / src / main / java / de / juplo / kafka / ApplicationConfiguration.java
index 566c7a3..766740b 100644 (file)
@@ -7,7 +7,6 @@ import org.apache.kafka.common.serialization.StringDeserializer;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.kafka.support.serializer.JsonDeserializer;
 
 import java.util.Properties;
 import java.util.concurrent.ExecutorService;
@@ -20,7 +19,7 @@ import java.util.function.Consumer;
 public class ApplicationConfiguration
 {
   @Bean
-  public Consumer<ConsumerRecord<String, ClientMessage>> consumer()
+  public Consumer<ConsumerRecord<String, Long>> consumer()
   {
     return (record) ->
     {
@@ -29,10 +28,10 @@ public class ApplicationConfiguration
   }
 
   @Bean
-  public EndlessConsumer<String, ClientMessage> endlessConsumer(
-      KafkaConsumer<String, ClientMessage> kafkaConsumer,
+  public EndlessConsumer<String, Long> endlessConsumer(
+      KafkaConsumer<String, Long> kafkaConsumer,
       ExecutorService executor,
-      Consumer<ConsumerRecord<String, ClientMessage>> handler,
+      Consumer<ConsumerRecord<String, Long>> handler,
       ApplicationProperties properties)
   {
     return
@@ -51,7 +50,7 @@ public class ApplicationConfiguration
   }
 
   @Bean(destroyMethod = "close")
-  public KafkaConsumer<String, ClientMessage> kafkaConsumer(ApplicationProperties properties)
+  public KafkaConsumer<String, Long> kafkaConsumer(ApplicationProperties properties)
   {
     Properties props = new Properties();
 
@@ -59,11 +58,10 @@ public class ApplicationConfiguration
     props.put("group.id", properties.getGroupId());
     props.put("client.id", properties.getClientId());
     props.put("auto.offset.reset", properties.getAutoOffsetReset());
+    props.put("auto.commit.interval.ms", (int)properties.getCommitInterval().toMillis());
     props.put("metadata.max.age.ms", "1000");
     props.put("key.deserializer", StringDeserializer.class.getName());
-    props.put("value.deserializer", JsonDeserializer.class.getName());
-    props.put(JsonDeserializer.VALUE_DEFAULT_TYPE, ClientMessage.class.getName());
-    props.put(JsonDeserializer.TRUSTED_PACKAGES, "de.juplo.kafka");
+    props.put("value.deserializer", LongDeserializer.class.getName());
 
     return new KafkaConsumer<>(props);
   }