- 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.getResult(),
- removed.getPartition(),
- counter.getKey());
- }
- repository.save(new StatisticsDocument(removed));
- });
- }
-
- @Override
- public void onPartitionsAssigned(Collection<TopicPartition> partitions)
- {
- partitions.forEach(tp ->
- {
- log.info("{} - adding partition: {}", id, tp);
- seen.put(
- tp,
- repository
- .findById(tp.toString())
- .map(PartitionStatistics::new)
- .orElse(new PartitionStatistics(tp)));
- });
- }
- });