Demonstration der RecordDeserializationException
[demos/kafka/training] / src / main / java / de / juplo / kafka / ApplicationConfiguration.java
index 58f44fa..4054e93 100644 (file)
@@ -1,5 +1,6 @@
 package de.juplo.kafka;
 
+import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.apache.kafka.clients.consumer.KafkaConsumer;
 import org.apache.kafka.common.serialization.LongDeserializer;
 import org.apache.kafka.common.serialization.StringDeserializer;
@@ -8,7 +9,9 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 import java.util.Properties;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.function.Consumer;
 
 
 @Configuration
@@ -16,20 +19,38 @@ import java.util.concurrent.Executors;
 public class ApplicationConfiguration
 {
   @Bean
-  public EndlessConsumer endlessConsumer(
-      KafkaConsumer<String, String> kafkaConsumer,
+  public Consumer<ConsumerRecord<String, Long>> consumer()
+  {
+    return (record) ->
+    {
+      // Handle record
+    };
+  }
+
+  @Bean
+  public EndlessConsumer<String, Long> endlessConsumer(
+      KafkaConsumer<String, Long> kafkaConsumer,
+      ExecutorService executor,
+      Consumer<ConsumerRecord<String, Long>> handler,
       ApplicationProperties properties)
   {
     return
-        new EndlessConsumer(
-            Executors.newFixedThreadPool(1),
+        new EndlessConsumer<>(
+            executor,
             properties.getClientId(),
             properties.getTopic(),
-            kafkaConsumer);
+            kafkaConsumer,
+            handler);
+  }
+
+  @Bean
+  public ExecutorService executor()
+  {
+    return Executors.newSingleThreadExecutor();
   }
 
   @Bean(destroyMethod = "close")
-  public KafkaConsumer<String, String> kafkaConsumer(ApplicationProperties properties)
+  public KafkaConsumer<String, Long> kafkaConsumer(ApplicationProperties properties)
   {
     Properties props = new Properties();