NEU
authorKai Moritz <kai@juplo.de>
Thu, 20 Apr 2023 09:35:57 +0000 (11:35 +0200)
committerKai Moritz <kai@juplo.de>
Thu, 20 Apr 2023 09:35:57 +0000 (11:35 +0200)
src/test/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaServicesConfiguration.java

index c157cce..4576973 100644 (file)
@@ -24,6 +24,7 @@ import java.time.Clock;
 import java.time.ZoneId;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 
 
 @ConditionalOnProperty(
@@ -68,7 +69,7 @@ public class KafkaServicesConfiguration
 
   @Bean
   Producer<Integer, ChatRoomTo>  chatRoomChannelProducer(
-      Map<String, Object> defaultProducerProperties,
+      Properties defaultProducerProperties,
       IntegerSerializer integerSerializer,
       JsonSerializer<ChatRoomTo> chatRoomSerializer)
   {
@@ -93,11 +94,12 @@ public class KafkaServicesConfiguration
 
   @Bean
   Consumer<Integer, ChatRoomTo>  chatRoomChannelConsumer(
-      Map<String, Object> defaultConsumerProperties,
+      Properties defaultConsumerProperties,
       IntegerDeserializer integerDeserializer,
       JsonDeserializer<ChatRoomTo> chatRoomDeserializer)
   {
-    Map<String, Object> properties = new HashMap<>(defaultConsumerProperties);
+    Map<String, Object> properties = new HashMap<>();
+    defaultConsumerProperties.forEach((key, value) -> properties.put(key.toString(), value));
     properties.put(
         ConsumerConfig.GROUP_ID_CONFIG,
         "chat_room_channel");
@@ -143,7 +145,7 @@ public class KafkaServicesConfiguration
 
   @Bean
   Producer<String, MessageTo>  chatMessageChannelProducer(
-      Map<String, Object> defaultProducerProperties,
+      Properties defaultProducerProperties,
       StringSerializer stringSerializer,
       JsonSerializer<MessageTo> messageSerializer)
   {
@@ -168,11 +170,12 @@ public class KafkaServicesConfiguration
 
   @Bean
   Consumer<String, MessageTo>  chatMessageChannelConsumer(
-      Map<String, Object> defaultConsumerProperties,
+      Properties defaultConsumerProperties,
       StringDeserializer stringDeserializer,
       JsonDeserializer<MessageTo> messageDeserializer)
   {
-    Map<String, Object> properties = new HashMap<>(defaultConsumerProperties);
+    Map<String, Object> properties = new HashMap<>();
+    defaultConsumerProperties.forEach((key, value) -> properties.put(key.toString(), value));
     properties.put(
         ConsumerConfig.GROUP_ID_CONFIG,
         "chat_message_channel");
@@ -196,27 +199,35 @@ public class KafkaServicesConfiguration
   }
 
   @Bean
-  Map<String, Object> defaultProducerProperties(ChatBackendProperties chatBackendProperties)
+  Properties defaultProducerProperties(ChatBackendProperties chatBackendProperties)
   {
-    return Map.of(
+    Properties properties = new Properties();
+    properties.setProperty(
         ProducerConfig.CLIENT_ID_CONFIG,
-        chatBackendProperties.getKafka().getClientId(),
+        chatBackendProperties.getKafka().getClientId());
+    properties.setProperty(
         ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
         chatBackendProperties.getKafka().getBootstrapServers());
+    return properties;
   }
 
   @Bean
-  Map<String, Object> defaultConsumerProperties(ChatBackendProperties chatBackendProperties)
+  Properties defaultConsumerProperties(ChatBackendProperties chatBackendProperties)
   {
-    return Map.of(
+    Properties properties = new Properties();
+    properties.setProperty(
         ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
-        chatBackendProperties.getKafka().getBootstrapServers(),
+        chatBackendProperties.getKafka().getBootstrapServers());
+    properties.setProperty(
         ConsumerConfig.CLIENT_ID_CONFIG,
-        chatBackendProperties.getKafka().getClientId(),
+        chatBackendProperties.getKafka().getClientId());
+    properties.setProperty(
         ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,
-        "false",
+        "false");
+    properties.setProperty(
         ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
         "earliest");
+    return properties;
   }
 
   @Bean