Die Offsets werden ausgegeben, wenn eine Partition zugeteilt/entzogen wird
authorKai Moritz <kai@juplo.de>
Sat, 9 Apr 2022 16:29:44 +0000 (18:29 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 9 Apr 2022 16:42:49 +0000 (18:42 +0200)
src/main/java/de/juplo/kafka/EndlessConsumer.java

index 2e79009..803c76e 100644 (file)
@@ -34,6 +34,7 @@ public class EndlessConsumer implements Runnable
   private Future<?> future = null;
 
   private final Map<Integer, Map<String, Long>> seen = new HashMap<>();
+  private final Map<Integer, Long> offsets = new HashMap<>();
 
 
   public EndlessConsumer(
@@ -76,15 +77,24 @@ public class EndlessConsumer implements Runnable
         {
           partitions.forEach(tp ->
           {
-            log.info("{} - removing partition: {}", id, tp);
-            Map<String, Long> 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<String, Long> 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<>());
           });
         }
       });