From: Kai Moritz Date: Sat, 9 Apr 2022 16:29:44 +0000 (+0200) Subject: Die Offsets werden ausgegeben, wenn eine Partition zugeteilt/entzogen wird X-Git-Tag: offset-endpoint~1 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=2b3dc634e091bc2de10f6f59e3f0372ef4311d9e;p=demos%2Fkafka%2Ftraining Die Offsets werden ausgegeben, wenn eine Partition zugeteilt/entzogen wird --- diff --git a/src/main/java/de/juplo/kafka/EndlessConsumer.java b/src/main/java/de/juplo/kafka/EndlessConsumer.java index 2e79009..803c76e 100644 --- a/src/main/java/de/juplo/kafka/EndlessConsumer.java +++ b/src/main/java/de/juplo/kafka/EndlessConsumer.java @@ -34,6 +34,7 @@ public class EndlessConsumer implements Runnable private Future future = null; private final Map> seen = new HashMap<>(); + private final Map offsets = new HashMap<>(); public EndlessConsumer( @@ -76,15 +77,24 @@ public class EndlessConsumer implements Runnable { partitions.forEach(tp -> { - log.info("{} - removing partition: {}", id, tp); - Map removed = seen.remove(tp.partition()); + Integer partition = tp.partition(); + Long newOffset = consumer.position(tp); + Long oldOffset = offsets.remove(partition); + log.info( + "{} - removing partition: {}, consumed {} records (offset {} -> {})", + id, + partition, + newOffset - oldOffset, + oldOffset, + newOffset); + Map removed = seen.remove(partition); for (String key : removed.keySet()) { log.info( "{} - Seen {} messages for partition={}|key={}", id, removed.get(key), - tp.partition(), + partition, key); } }); @@ -95,8 +105,11 @@ public class EndlessConsumer implements Runnable { partitions.forEach(tp -> { - log.info("{} - adding partition: {}", id, tp); - seen.put(tp.partition(), new HashMap<>()); + Integer partition = tp.partition(); + Long offset = consumer.position(tp); + log.info("{} - adding partition: {}, offset={}", id, partition, offset); + offsets.put(partition, offset); + seen.put(partition, new HashMap<>()); }); } });