From 2b3dc634e091bc2de10f6f59e3f0372ef4311d9e 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 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<>()); }); } }); -- 2.20.1