From: Kai Moritz Date: Mon, 1 Aug 2022 21:07:55 +0000 (+0200) Subject: Angleichungen zwischen Producer/Consumer X-Git-Tag: spikzettel-DEPRECATED^2~3^2 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=badfc4b6fa99dc6f7fa9ffde004a82b8539bc4ec;p=demos%2Fkafka%2Ftraining Angleichungen zwischen Producer/Consumer --- diff --git a/src/main/java/de/juplo/kafka/SimpleProducer.java b/src/main/java/de/juplo/kafka/SimpleProducer.java index fd03d73..9fcaa6e 100644 --- a/src/main/java/de/juplo/kafka/SimpleProducer.java +++ b/src/main/java/de/juplo/kafka/SimpleProducer.java @@ -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(); } }