1 package de.juplo.kafka;
3 import lombok.extern.slf4j.Slf4j;
4 import org.apache.kafka.clients.consumer.ConsumerRecord;
6 import java.util.HashMap;
11 public class KeyCountingRecordHandler implements RecordHandler<String, Long>
13 private final Map<Integer, Map<String, Long>> seen = new HashMap<>();
17 public void accept(ConsumerRecord<String, Long> record)
19 Integer partition = record.partition();
20 String key = record.key() == null ? "NULL" : record.key().toString();
21 Map<String, Long> byKey = seen.get(partition);
23 if (!byKey.containsKey(key))
26 long seenByKey = byKey.get(key);
28 byKey.put(key, seenByKey);
31 public void addPartition(Integer partition, Map<String, Long> statistics)
33 seen.put(partition, statistics);
36 public Map<String, Long> removePartition(Integer partition)
38 return seen.remove(partition);
42 public Map<Integer, Map<String, Long>> getSeen()