Fehlermeldung & Abbruch anstatt hartkodierter Standard-Konfig grundlagen/simple-consumer grundlagen/simple-consumer--2025-03-18--19-42 grundlagen/simple-consumer--2025-03-signal grundlagen/simple-consumer--2025-04-signal
authorKai Moritz <kai@juplo.de>
Wed, 12 Mar 2025 05:44:27 +0000 (06:44 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 14 Mar 2025 15:51:25 +0000 (16:51 +0100)
src/main/java/de/juplo/kafka/ExampleConsumer.java

index 891af89..865e5cb 100644 (file)
@@ -98,25 +98,26 @@ public class ExampleConsumer
 
   public static void main(String[] args) throws Exception
   {
-    String broker = ":9092";
-    String topic = "test";
-    String groupId = "my-group";
-    String clientId = "DEV";
-
-    switch (args.length)
+    if (args.length != 4)
     {
-      case 4:
-        clientId = args[3];
-      case 3:
-        groupId = args[2];
-      case 2:
-        topic = args[1];
-      case 1:
-        broker = args[0];
+      log.error("Four arguments required!");
+      log.error("args[0]: Broker-Address");
+      log.error("args[1]: Topic");
+      log.error("args[2]: Group-ID");
+      log.error("args[3]: Unique Client-ID");
+      System.exit(1);
+      return;
     }
 
 
-    ExampleConsumer instance = new ExampleConsumer(broker, topic, groupId, clientId);
+    log.info(
+      "Running ExampleConsumer: broker={}, topic={}, group-id={}, client-id={}",
+      args[0],
+      args[1],
+      args[2],
+      args[3]);
+
+    ExampleConsumer instance = new ExampleConsumer(args[0], args[1], args[2], args[3]);
 
     Runtime.getRuntime().addShutdownHook(new Thread(() ->
     {
@@ -134,12 +135,7 @@ public class ExampleConsumer
       log.info("Shutdown completed.");
     }));
 
-    log.info(
-      "Running ExampleConsumer: broker={}, topic={}, group-id={}, client-id={}",
-      broker,
-      topic,
-      groupId,
-      clientId);
     instance.run();
   }
 }
+