From: Kai Moritz Date: Tue, 5 Apr 2022 20:37:55 +0000 (+0200) Subject: Report über gesehene Schlüssel wiederbelebt X-Git-Tag: offset-endpoint~8 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=f20231dcb36eaeee69e07192b5785bc59abc1dc1;p=demos%2Fkafka%2Ftraining Report über gesehene Schlüssel wiederbelebt * An der alten Stelle war die Map ja jetzt nur noch leer, da dem Consumer zu dem Zeitpunkt, an dem die gesehen Schlüssel ausgegeben wurden, bereits alle Partitionen entzogen worden sind. * Daher werden die gesehenen Schlüssel jetzt ausgegeben, wenn eine Partition entzogen wird. --- diff --git a/src/main/java/de/juplo/kafka/EndlessConsumer.java b/src/main/java/de/juplo/kafka/EndlessConsumer.java index 9aa8152..be371ae 100644 --- a/src/main/java/de/juplo/kafka/EndlessConsumer.java +++ b/src/main/java/de/juplo/kafka/EndlessConsumer.java @@ -74,13 +74,30 @@ public class EndlessConsumer implements Runnable @Override public void onPartitionsRevoked(Collection partitions) { - partitions.forEach(tp -> seen.remove(tp.partition())); + partitions.forEach(tp -> + { + log.info("{} - removing partition: {}", id, tp); + Map removed = seen.remove(tp.partition()); + for (String key : removed.keySet()) + { + log.info( + "{} - Seen {} messages for partition={}|key={}", + id, + removed.get(key), + removed, + key); + } + }); } @Override public void onPartitionsAssigned(Collection partitions) { - partitions.forEach(tp -> seen.put(tp.partition(), new HashMap<>())); + partitions.forEach(tp -> + { + log.info("{} - adding partition: {}", id, tp); + seen.put(tp.partition(), new HashMap<>()); + }); } }); @@ -130,21 +147,6 @@ public class EndlessConsumer implements Runnable { log.info("{} - Closing the KafkaConsumer", id); consumer.close(); - - for (Integer partition : seen.keySet()) - { - Map byKey = seen.get(partition); - for (String key : byKey.keySet()) - { - log.info( - "{} - Seen {} messages for partition={}|key={}", - id, - byKey.get(key), - partition, - key); - } - } - log.info("{} - Consumer-Thread exiting", id); } }