private KafkaConsumer<String, String> consumer = null;
private Future<?> future = null;
- private final Map<TopicPartition, PartitionStatistics> seen = new HashMap<>();
+ private final Map<Integer, Map<String, Integer>> seen = new HashMap<>();
public EndlessConsumer(
partitions.forEach(tp ->
{
log.info("{} - removing partition: {}", id, tp);
- PartitionStatistics removed = seen.remove(tp);
- for (KeyCounter counter : removed.getStatistics())
+ Map<String, Integer> removed = seen.remove(tp.partition());
+ for (String key : removed.keySet())
{
log.info(
"{} - Seen {} messages for partition={}|key={}",
id,
- counter.getCounter(),
- removed.getPartition(),
- counter.getKey());
+ removed.get(key),
+ tp.partition(),
+ key);
}
});
}
partitions.forEach(tp ->
{
log.info("{} - adding partition: {}", id, tp);
- seen.put(tp, new PartitionStatistics(tp));
+ seen.put(tp.partition(), new HashMap<>());
});
}
});
record.value()
);
- TopicPartition partition = new TopicPartition(record.topic(), record.partition());
+ Integer partition = record.partition();
String key = record.key() == null ? "NULL" : record.key();
- seen.get(partition).increment(key);
+ Map<String, Integer> byKey = seen.get(partition);
+
+ if (!byKey.containsKey(key))
+ byKey.put(key, 0);
+
+ int seenByKey = byKey.get(key);
+ seenByKey++;
+ byKey.put(key, seenByKey);
}
}
}
}
}
- public Map<TopicPartition, PartitionStatistics> getSeen()
+ public Map<Integer, Map<String, Integer>> getSeen()
{
return seen;
}