Refaktorisierung für Tests - ExecutorService als separate Bean erzeugt
authorKai Moritz <kai@juplo.de>
Sat, 9 Apr 2022 11:21:43 +0000 (13:21 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 10 Apr 2022 20:26:39 +0000 (22:26 +0200)
src/main/java/de/juplo/kafka/ApplicationConfiguration.java

index 58f44fa..76d0c8a 100644 (file)
@@ -8,6 +8,7 @@ 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;
 
 
@@ -18,16 +19,23 @@ public class ApplicationConfiguration
   @Bean
   public EndlessConsumer endlessConsumer(
       KafkaConsumer<String, String> kafkaConsumer,
+      ExecutorService executor,
       ApplicationProperties properties)
   {
     return
         new EndlessConsumer(
-            Executors.newFixedThreadPool(1),
+            executor,
             properties.getClientId(),
             properties.getTopic(),
             kafkaConsumer);
   }
 
+  @Bean
+  public ExecutorService executor()
+  {
+    return Executors.newSingleThreadExecutor();
+  }
+
   @Bean(destroyMethod = "close")
   public KafkaConsumer<String, String> kafkaConsumer(ApplicationProperties properties)
   {