From: Kai Moritz Date: Sun, 27 Oct 2024 12:03:25 +0000 (+0100) Subject: Die Counter werden mit dem ``String``-Key indiziert X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=e2e7ed4987ac9fcabb313a948f022e98e9c9e0a7;p=demos%2Fkafka%2Ftraining Die Counter werden mit dem ``String``-Key indiziert * Vorbereitung auf eine Poison-Pill Übung ist hier noch out-of-scope... --- diff --git a/src/main/java/de/juplo/kafka/ExampleConsumer.java b/src/main/java/de/juplo/kafka/ExampleConsumer.java index 85b77b9..e400c4e 100644 --- a/src/main/java/de/juplo/kafka/ExampleConsumer.java +++ b/src/main/java/de/juplo/kafka/ExampleConsumer.java @@ -21,7 +21,7 @@ public class ExampleConsumer implements Runnable private final Thread workerThread; private final Runnable closeCallback; - private final Map counterState = new HashMap<>(); + private final Map counterState = new HashMap<>(); private volatile boolean running = false; private long consumed = 0; @@ -98,9 +98,8 @@ public class ExampleConsumer implements Runnable { consumed++; log.info("{} - {}: {}/{} - {}={}", id, offset, topic, partition, key, value); - Integer counted = Integer.parseInt(key); - Long counter = counterState.compute(counted, (k, v) -> v == null ? 1l : v + 1); - log.info("{} - current value for counter {}: {}", id, counted, counter); + Long counter = counterState.compute(key, (k, v) -> v == null ? 1l : v + 1); + log.info("{} - current value for counter {}: {}", id, key, counter); }