RÜCKBAU für Rebase der Folge-Branches
authorKai Moritz <kai@juplo.de>
Wed, 12 Mar 2025 05:53:08 +0000 (06:53 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 14 Mar 2025 15:51:25 +0000 (16:51 +0100)
src/main/java/de/juplo/kafka/ExampleProducer.java

index b4051fb..c3db7e7 100644 (file)
@@ -116,23 +116,21 @@ public class ExampleProducer
 
   public static void main(String[] args) throws Exception
   {
-    if (args.length != 3)
+    String broker = ":9092";
+    String topic = "test";
+    String clientId = "DEV";
+
+    switch (args.length)
     {
-      log.error("Three arguments required!");
-      log.error("arg[0]: Broker-Address");
-      log.error("arg[1]: Topic");
-      log.error("arg[2]: Unique Client-ID");
-      System.exit(1);
-      return;
+      case 3:
+        clientId = args[2];
+      case 2:
+        topic = args[1];
+      case 1:
+        broker = args[0];
     }
 
-    log.info(
-      "Running ExampleProducer: broker={}, topic={}, client-id={}",
-      args[0],
-      args[1],
-      args[2]);
-
-    ExampleProducer instance = new ExampleProducer(args[0], args[1], args[2]);
+    ExampleProducer instance = new ExampleProducer(broker, topic, clientId);
 
     Runtime.getRuntime().addShutdownHook(new Thread(() ->
     {
@@ -149,6 +147,11 @@ public class ExampleProducer
       log.info("Shutdown completed.");
     }));
 
+    log.info(
+      "Running ExampleProducer: broker={}, topic={}, client-id={}",
+      broker,
+      topic,
+      clientId);
     instance.run();
   }
 }