From b654c5c0f6534a9967b2d70c39c11402f03c597e Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 9 Jun 2023 11:16:42 +0200 Subject: [PATCH] Beispiele verwenden das Interface, um die erzeugte Instanz abzulegen --- src/main/java/de/juplo/kafka/SimpleConsumer.java | 5 +++-- src/main/java/de/juplo/kafka/SimpleProducer.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/juplo/kafka/SimpleConsumer.java b/src/main/java/de/juplo/kafka/SimpleConsumer.java index d8f3624..913ffd5 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; @@ -19,7 +20,7 @@ import java.util.concurrent.locks.ReentrantLock; public class SimpleConsumer { private long consumed = 0; - private KafkaConsumer consumer; + private Consumer consumer; private Lock lock = new ReentrantLock(); private Condition stopped = lock.newCondition(); @@ -36,7 +37,7 @@ public class SimpleConsumer props.put("key.deserializer", StringDeserializer.class.getName()); props.put("value.deserializer", StringDeserializer.class.getName()); - KafkaConsumer consumer = new KafkaConsumer<>(props); + Consumer consumer = new KafkaConsumer<>(props); // end::create[] this.consumer = consumer; } diff --git a/src/main/java/de/juplo/kafka/SimpleProducer.java b/src/main/java/de/juplo/kafka/SimpleProducer.java index 43a7227..9a1d5d6 100644 --- a/src/main/java/de/juplo/kafka/SimpleProducer.java +++ b/src/main/java/de/juplo/kafka/SimpleProducer.java @@ -1,6 +1,7 @@ package de.juplo.kafka; import lombok.extern.slf4j.Slf4j; +import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.common.serialization.StringSerializer; @@ -15,7 +16,7 @@ public class SimpleProducer { private final String id; private final String topic; - private final KafkaProducer producer; + private final Producer producer; private long produced = 0; @@ -27,7 +28,7 @@ public class SimpleProducer props.put("key.serializer", StringSerializer.class.getName()); props.put("value.serializer", StringSerializer.class.getName()); - KafkaProducer producer = new KafkaProducer<>(props); + Producer producer = new KafkaProducer<>(props); // end::create[] this.id = clientId; -- 2.20.1