Rückbau der Berücksichtigung von `auto.offset.rest`, wenn Offset unbekannt
[demos/kafka/training] / src / main / java / de / juplo / kafka / ApplicationRebalanceListener.java
index 3653197..da72555 100644 (file)
@@ -33,17 +33,12 @@ public class ApplicationRebalanceListener implements RebalanceListener
           stateRepository
               .findById(Integer.toString(partition))
               .orElse(new StateDocument(partition));
-      if (document.offset >= 0)
-      {
-        // Only seek, if a stored offset was found
-        // Otherwise: Use initial offset, generated by Kafka
-        consumer.seek(tp, document.offset);
-        log.info(
-            "{} - Seeking to offset {} for partition {}",
-            id,
-            document.offset,
-            partition);
-      }
+      log.info(
+        "{} - Offset of next unseen message for partition {}: {}",
+        id,
+        partition,
+        document.offset);
+      consumer.seek(tp, document.offset);
       recordHandler.addPartition(partition, document.state);
       for (String user : document.state.keySet())
       {
@@ -86,34 +81,4 @@ public class ApplicationRebalanceListener implements RebalanceListener
       stateRepository.save(new StateDocument(partition, state, results, offset));
     });
   }
-
-
-  @Override
-  public void beforeNextPoll()
-  {
-    partitions
-      .stream()
-      .forEach(partition ->
-      {
-        log.info("{} - persisting state & offset for partition: {}", id, partition);
-        Map<String, AdderResult> state = recordHandler.getState(partition).getState();
-        Long offset = consumer.position(new TopicPartition(topic, partition));
-        log.info(
-          "{} - offset of next unseen message for partition {} is {}",
-          id,
-          partition,
-          offset);
-        for (String user : state.keySet())
-        {
-          log.info(
-            "{} - Saved state for partition={}|user={}: {}",
-            id,
-            partition,
-            user,
-            state.get(user));
-        }
-        Map<String, List<AdderResult>> results = adderResults.getState(partition);
-        stateRepository.save(new StateDocument(partition, state, results, offset));
-      });
-  }
 }