package de.juplo.kafka;
+import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import java.time.Clock;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
@Bean
public ApplicationRebalanceListener rebalanceListener(
- KafkaConsumer<String, String> kafkaConsumer,
ApplicationRecordHandler recordHandler,
AdderResults adderResults,
StateRepository stateRepository,
+ Consumer<String, String> consumer,
ApplicationProperties properties)
{
return new ApplicationRebalanceListener(
- kafkaConsumer,
recordHandler,
adderResults,
stateRepository,
- properties.getClientId());
+ properties.getClientId(),
+ consumer);
}
@Bean
@Slf4j
public class ApplicationRebalanceListener implements ConsumerRebalanceListener
{
- private final Consumer consumer;
private final ApplicationRecordHandler recordHandler;
private final AdderResults adderResults;
private final StateRepository stateRepository;
private final String id;
+ private final Consumer consumer;
private final Set<Integer> partitions = new HashSet<>();
public void onPartitionsRevoked(Collection<TopicPartition> partitions)
{
log.info("{} - Commiting offsets for all previously assigned partitions", id);
- consumer.commitSync();
+ try
+ {
+ consumer.commitSync();
+ }
+ catch (Exception e)
+ {
+ log.warn("{} - Could not commit offsets in onPartitionsRevoked():", id, e);
+ }
partitions.forEach(tp ->
{