- consumer.subscribe(Arrays.asList(topic), new ConsumerRebalanceListener()
- {
- @Override
- public void onPartitionsRevoked(Collection<TopicPartition> partitions)
- {
- partitions.forEach(tp ->
- {
- log.info("{} - removing partition: {}", id, tp);
- PartitionStatistics removed = seen.remove(tp);
- for (KeyCounter counter : removed.getStatistics())
- {
- log.info(
- "{} - Seen {} messages for partition={}|key={}",
- id,
- counter.getCounter(),
- removed.getPartition(),
- counter.getKey());
- }
- });
- }
-
- @Override
- public void onPartitionsAssigned(Collection<TopicPartition> partitions)
- {
- partitions.forEach(tp ->
- {
- log.info("{} - adding partition: {}", id, tp);
- seen.put(tp, new PartitionStatistics(tp));
- });
- }
- });