Der Consumer kann mit mehreren Topics konfiguriert werden spring/spring-consumer
authorKai Moritz <kai@juplo.de>
Fri, 1 Dec 2023 16:37:51 +0000 (17:37 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 1 Dec 2023 16:37:51 +0000 (17:37 +0100)
README.sh
docker/docker-compose.yml
pom.xml
src/main/java/de/juplo/kafka/ApplicationConfiguration.java
src/main/java/de/juplo/kafka/ApplicationProperties.java
src/main/java/de/juplo/kafka/SimpleConsumer.java
src/main/resources/application.yml

index b32d9f5..5e265f9 100755 (executable)
--- a/README.sh
+++ b/README.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-IMAGE=juplo/spring-consumer:1.0-SNAPSHOT
+IMAGE=juplo/spring-consumer:1.1-SNAPSHOT
 
 if [ "$1" = "cleanup" ]
 then
index 715dd8e..e4191ec 100644 (file)
@@ -218,6 +218,7 @@ services:
   consumer:
     image: juplo/spring-consumer:1.0-SNAPSHOT
     environment:
+      simple.consumer.topics: test
       spring.kafka.bootstrap-servers: kafka:9092
       spring.kafka.client-id: consumer
 
diff --git a/pom.xml b/pom.xml
index d5a28ea..f688913 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,7 @@
   <artifactId>spring-consumer</artifactId>
   <name>Spring Consumer</name>
   <description>Super Simple Consumer-Group, that is implemented as Spring-Boot application and configured by Spring Kafka</description>
-  <version>1.0-SNAPSHOT</version>
+  <version>1.1-SNAPSHOT</version>
 
   <properties>
     <java.version>17</java.version>
index 62d61a2..9a237b7 100644 (file)
@@ -22,7 +22,7 @@ public class ApplicationConfiguration
     return
         new SimpleConsumer(
             kafkaProperties.getClientId(),
-            applicationProperties.getTopic(),
+            applicationProperties.getTopics(),
             kafkaConsumer);
   }
 
index a4cc8b8..4092fa2 100644 (file)
@@ -17,5 +17,5 @@ public class ApplicationProperties
 {
   @NotNull
   @NotEmpty
-  private String topic;
+  private String[] topics;
 }
index aadc11f..a76132b 100644 (file)
@@ -17,7 +17,7 @@ import java.util.concurrent.Callable;
 public class SimpleConsumer implements Callable<Integer>
 {
   private final String id;
-  private final String topic;
+  private final String[] topics;
   private final Consumer<String, String> consumer;
 
   private long consumed = 0;
@@ -28,8 +28,8 @@ public class SimpleConsumer implements Callable<Integer>
   {
     try
     {
-      log.info("{} - Subscribing to topic {}", id, topic);
-      consumer.subscribe(Arrays.asList(topic));
+      log.info("{} - Subscribing to topics: {}", id, topics);
+      consumer.subscribe(Arrays.asList(topics));
 
       while (true)
       {
index b7fedad..5143336 100644 (file)
@@ -1,6 +1,6 @@
 simple:
   consumer:
-    topic: test
+    topics: test
 management:
   endpoint:
     shutdown: