Beispiele verwenden das Interface, um die erzeugte Instanz abzulegen
authorKai Moritz <kai@juplo.de>
Fri, 9 Jun 2023 09:16:42 +0000 (11:16 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 9 Jun 2023 09:16:42 +0000 (11:16 +0200)
src/main/java/de/juplo/kafka/SimpleConsumer.java
src/main/java/de/juplo/kafka/SimpleProducer.java

index d8f3624..913ffd5 100644 (file)
@@ -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<String, String> consumer;
+  private Consumer<String, String> 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<String, String> consumer = new KafkaConsumer<>(props);
+    Consumer<String, String> consumer = new KafkaConsumer<>(props);
     // end::create[]
     this.consumer = consumer;
   }
index 43a7227..9a1d5d6 100644 (file)
@@ -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<String, String> producer;
+  private final Producer<String, String> 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<String, String> producer = new KafkaProducer<>(props);
+    Producer<String, String> producer = new KafkaProducer<>(props);
     // end::create[]
 
     this.id = clientId;