From d1ce252495c63a971d1734a35b10cf26313d95fb Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 9 Apr 2022 18:29:44 +0200 Subject: [PATCH] Die Offsets werden ausgegeben, wenn eine Partition zugeteilt/entzogen wird --- .../java/de/juplo/kafka/EndlessConsumer.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/juplo/kafka/EndlessConsumer.java b/src/main/java/de/juplo/kafka/EndlessConsumer.java index bc3d357..6af3765 100644 --- a/src/main/java/de/juplo/kafka/EndlessConsumer.java +++ b/src/main/java/de/juplo/kafka/EndlessConsumer.java @@ -38,6 +38,7 @@ public class EndlessConsumer implements Runnable private final Map> seen = new HashMap<>(); + private final Map offsets = new HashMap<>(); public EndlessConsumer( @@ -80,15 +81,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); } }); @@ -99,8 +109,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<>()); }); } }); -- 2.20.1