import org.apache.kafka.clients.consumer.ConsumerRebalanceListener;
import org.apache.kafka.common.TopicPartition;
-import java.time.Clock;
-import java.time.Duration;
-import java.time.Instant;
import java.util.*;
-import java.util.concurrent.CountDownLatch;
@RequiredArgsConstructor
public void onPartitionsRevoked(Collection<TopicPartition> partitions)
{
log.info("{} - Commiting offsets for all previously assigned partitions", id);
- CountDownLatch commitDone = new CountDownLatch(1);
- consumer.commitAsync((offsets, e) ->
- {
- commitDone.countDown();
- if (e == null)
- {
- log.error("{} - Could not commit offsets to Kafka!", id, e);
- }
- else
- {
- offsets.entrySet().stream().forEach(entry ->
- {
- log.info("{} - Commited offset for {}: {}", id, entry.getKey(), entry.getValue());
- });
- }
- });
+ consumer.commitSync();
partitions.forEach(tp ->
{
Map<String, List<AdderResult>> results = adderResults.removePartition(partition);
stateRepository.save(new StateDocument(partition, state, results));
});
-
- try
- {
- log.debug("{} - Waiting for async commit to complete", id);
- commitDone.await();
- }
- catch (InterruptedException e)
- {
- log.warn(
- "{} - Interrupted while waiting for async commit in onPartitionsRevoked({})",
- id,
- partitions,
- e);
- }
}
}