Angleichungen zwischen Producer/Consumer
authorKai Moritz <kai@juplo.de>
Mon, 1 Aug 2022 21:07:55 +0000 (23:07 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 1 Aug 2022 21:14:01 +0000 (23:14 +0200)
src/main/java/de/juplo/kafka/SimpleProducer.java

index fd03d73..9fcaa6e 100644 (file)
@@ -19,18 +19,18 @@ public class SimpleProducer
   private volatile boolean running = true;
   private volatile boolean done = false;
 
-  public SimpleProducer(String broker, String topic, String id)
+  public SimpleProducer(String broker, String topic, String clientId)
   {
     Properties props = new Properties();
     props.put("bootstrap.servers", broker);
-    props.put("client.id", id); // Nur zur Wiedererkennung
+    props.put("client.id", clientId); // Nur zur Wiedererkennung
     props.put("key.serializer", StringSerializer.class.getName());
     props.put("value.serializer", StringSerializer.class.getName());
 
     producer = new KafkaProducer<>(props);
 
     this.topic = topic;
-    this.id = id;
+    this.id = clientId;
   }
 
   public void run()
@@ -124,14 +124,14 @@ public class SimpleProducer
         broker = args[0];
     }
 
-    SimpleProducer producer = new SimpleProducer(broker, topic, clientId);
+    SimpleProducer instance = new SimpleProducer(broker, topic, clientId);
 
     Runtime.getRuntime().addShutdownHook(new Thread(() ->
     {
-      producer.running = false;
-      while (!producer.done)
+      instance.running = false;
+      while (!instance.done)
       {
-        log.info("Waiting for producer...");
+        log.info("Waiting for main-thread...");
         try
         {
           Thread.sleep(1000);
@@ -142,10 +142,10 @@ public class SimpleProducer
     }));
 
     log.info(
-        "Running simple producer: broker={}, topic={}, client-id={}",
+        "Running SimpleProducer: broker={}, topic={}, client-id={}",
         broker,
         topic,
         clientId);
-    producer.run();
+    instance.run();
   }
 }