From: Kai Moritz Date: Sat, 3 Sep 2022 06:29:53 +0000 (+0200) Subject: Code an die anderen Implementierungen angepasst X-Git-Tag: sumup-adder---lvm-2-tage~1 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;ds=sidebyside;h=b38bb9d1cbee6b9fe2d5af0a218bbc1e9767c3b7;p=demos%2Fkafka%2Ftraining Code an die anderen Implementierungen angepasst --- diff --git a/src/main/java/de/juplo/kafka/ApplicationRebalanceListener.java b/src/main/java/de/juplo/kafka/ApplicationRebalanceListener.java index 8e8464f..f3e6c8a 100644 --- a/src/main/java/de/juplo/kafka/ApplicationRebalanceListener.java +++ b/src/main/java/de/juplo/kafka/ApplicationRebalanceListener.java @@ -74,15 +74,15 @@ public class ApplicationRebalanceListener implements RebalanceListener Integer partition = tp.partition(); log.info("{} - removing partition: {}", id, partition); this.partitions.remove(partition); - Long offset = consumer.position(tp); if (commitsEnabled) { + Map state = recordHandler.removePartition(partition); + Long offset = consumer.position(tp); log.info( - "{} - Storing {} as offset of next message for partition {}", + "{} - offset of next unseen message for partition {} is {}", id, - offset, - partition); - Map state = recordHandler.removePartition(partition); + partition, + offset); for (String user : state.keySet()) { log.info( @@ -114,13 +114,31 @@ public class ApplicationRebalanceListener implements RebalanceListener if (lastCommit.plus(commitInterval).isBefore(clock.instant())) { - log.debug("{} - Storing data and offsets, last commit: {}", id, lastCommit); - partitions.forEach(partition -> stateRepository.save( - new StateDocument( + partitions + .stream() + .forEach(partition -> + { + log.info("{} - persisting state & offset for partition: {}", id, partition); + Map 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, - recordHandler.getState(partition).getState(), - adderResults.getState(partition), - consumer.position(new TopicPartition(topic, partition))))); + user, + state.get(user)); + } + Map> results = adderResults.getState(partition); + stateRepository.save(new StateDocument(partition, state, results, offset)); + }); + lastCommit = clock.instant(); } }