From: Kai Moritz Date: Fri, 9 Jun 2023 09:16:42 +0000 (+0200) Subject: Beispiele verwenden das Interface, um die erzeugte Instanz abzulegen X-Git-Tag: grundlagen/simple-consumer---2023-06-signal~4 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=8b87f6dc6958b8622c37f7154e57abb0672ffa16;p=demos%2Fkafka%2Ftraining Beispiele verwenden das Interface, um die erzeugte Instanz abzulegen --- diff --git a/src/main/java/de/juplo/kafka/SimpleConsumer.java b/src/main/java/de/juplo/kafka/SimpleConsumer.java index 9741e67..cee2165 100644 --- a/src/main/java/de/juplo/kafka/SimpleConsumer.java +++ b/src/main/java/de/juplo/kafka/SimpleConsumer.java @@ -3,6 +3,7 @@ package de.juplo.kafka; import lombok.extern.slf4j.Slf4j; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.Consumer; import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.common.errors.WakeupException; import org.apache.kafka.common.serialization.StringDeserializer; @@ -17,7 +18,7 @@ public class SimpleConsumer { private final String id; private final String topic; - private final KafkaConsumer consumer; + private final Consumer consumer; private volatile boolean running = false; private long consumed = 0; @@ -33,10 +34,9 @@ public class SimpleConsumer props.put("key.deserializer", StringDeserializer.class.getName()); props.put("value.deserializer", StringDeserializer.class.getName()); - consumer = new KafkaConsumer<>(props); - - this.topic = topic; this.id = clientId; + this.topic = topic; + consumer = new KafkaConsumer<>(props); }