fix: In `onPartitionsAssigned()` wurde der Kafka-Offset ausgegeben
[demos/kafka/training] / src / main / java / de / juplo / kafka / ApplicationRebalanceListener.java
index 2fccb4f..59b420a 100644 (file)
@@ -32,12 +32,11 @@ public class ApplicationRebalanceListener implements PollIntervalAwareConsumerRe
     partitions.forEach(tp ->
     {
       Integer partition = tp.partition();
-      Long offset = consumer.position(tp);
-      log.info("{} - adding partition: {}, offset={}", id, partition, offset);
       StateDocument document =
           stateRepository
               .findById(Integer.toString(partition))
               .orElse(new StateDocument(partition));
+      log.info("{} - adding partition: {}, offset={}", id, partition, document.offset);
       if (document.offset >= 0)
       {
         // Only seek, if a stored offset was found
@@ -54,14 +53,14 @@ public class ApplicationRebalanceListener implements PollIntervalAwareConsumerRe
     partitions.forEach(tp ->
     {
       Integer partition = tp.partition();
-      Long newOffset = consumer.position(tp);
+      Long offset = consumer.position(tp);
       log.info(
           "{} - removing partition: {}, offset of next message {})",
           id,
           partition,
-          newOffset);
+          offset);
       Map<String, Long> removed = recordHandler.removePartition(partition);
-      stateRepository.save(new StateDocument(partition, removed, consumer.position(tp)));
+      stateRepository.save(new StateDocument(partition, removed, offset));
     });
   }