- consumer.subscribe(Arrays.asList(topic), new ConsumerRebalanceListener()
- {
- @Override
- public void onPartitionsRevoked(Collection<TopicPartition> partitions)
- {
- partitions.forEach(tp ->
- {
- log.info("{} - removing partition: {}", id, tp);
- Map<String, Integer> removed = seen.remove(tp.partition());
- for (String key : removed.keySet())
- {
- log.info(
- "{} - Seen {} messages for partition={}|key={}",
- id,
- removed.get(key),
- tp.partition(),
- key);
- }
- repository.save(new StatisticsDocument(tp.partition(), removed));
- });
- }
-
- @Override
- public void onPartitionsAssigned(Collection<TopicPartition> partitions)
- {
- partitions.forEach(tp ->
- {
- log.info("{} - adding partition: {}", id, tp);
- seen.put(
- tp.partition(),
- repository
- .findById(Integer.toString(tp.partition()))
- .map(document -> document.statistics)
- .orElse(new HashMap<>()));
- });
- }
- });