Class SeekUtils
java.lang.Object
org.springframework.kafka.listener.SeekUtils
Seek utilities.
- Since:
- 2.2
- Author:
- Gary Russell, Francois Rosiere, Wang Zhiyang
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FixedBackOff
The default back off - aFixedBackOff
with 0 interval andDEFAULT_MAX_FAILURES
- 1 retry attempts.static final int
The number of times a topic/partition/offset can fail before being rejected. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
doSeeks
(List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Exception exception, boolean recoverable, BiPredicate<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, Exception> skipper, LogAccessor logger) Seek records to earliest position, optionally skipping the first.static boolean
doSeeks
(List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Exception exception, boolean recoverable, RecoveryStrategy recovery, MessageListenerContainer container, LogAccessor logger) Seek records to earliest position, optionally skipping the first.static void
doSeeksToBegin
(List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, LogAccessor logger) Seek records to begin position, optionally skipping the first.static boolean
isBackoffException
(Exception exception) Return true if the exception is aKafkaBackoffException
.static void
seekOrRecover
(Exception thrownException, List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, boolean commitRecovered, BiPredicate<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, Exception> skipPredicate, LogAccessor logger, KafkaException.Level level) Seek the remaining records, optionally recovering the first.static void
seekOrRecover
(Exception thrownException, List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, boolean commitRecovered, RecoveryStrategy recovery, LogAccessor logger, KafkaException.Level level) Seek the remaining records, optionally recovering the first.static void
seekPartitions
(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Map<org.apache.kafka.common.TopicPartition, Long> partitions, LogAccessor logger) Perform seek operations on each partition.
-
Field Details
-
DEFAULT_MAX_FAILURES
public static final int DEFAULT_MAX_FAILURESThe number of times a topic/partition/offset can fail before being rejected.- See Also:
-
DEFAULT_BACK_OFF
The default back off - aFixedBackOff
with 0 interval andDEFAULT_MAX_FAILURES
- 1 retry attempts.
-
-
Method Details
-
doSeeks
public static boolean doSeeks(List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Exception exception, boolean recoverable, BiPredicate<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, Exception> skipper, LogAccessor logger) Seek records to earliest position, optionally skipping the first.- Parameters:
records
- the records.consumer
- the consumer.exception
- the exceptionrecoverable
- true if skipping the first record is allowed.skipper
- function to determine whether or not to skip seeking the first.logger
- aLogAccessor
for seek errors.- Returns:
- true if the failed record was skipped.
-
doSeeks
public static boolean doSeeks(List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Exception exception, boolean recoverable, RecoveryStrategy recovery, @Nullable MessageListenerContainer container, LogAccessor logger) Seek records to earliest position, optionally skipping the first.- Parameters:
records
- the records.consumer
- the consumer.exception
- the exceptionrecoverable
- true if skipping the first record is allowed.recovery
- theRecoveryStrategy
.container
- the container, or parent if a child.logger
- aLogAccessor
for seek errors.- Returns:
- true if the failed record was skipped.
-
doSeeksToBegin
public static void doSeeksToBegin(List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, LogAccessor logger) Seek records to begin position, optionally skipping the first.- Parameters:
records
- the records.consumer
- the consumer.logger
- aLogAccessor
for seek errors.- Since:
- 3.2
-
seekPartitions
public static void seekPartitions(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Map<org.apache.kafka.common.TopicPartition, Long> partitions, LogAccessor logger) Perform seek operations on each partition.- Parameters:
consumer
- the consumer.partitions
- the partitions.logger
- the logger.- Since:
- 2.5
-
seekOrRecover
public static void seekOrRecover(Exception thrownException, List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, boolean commitRecovered, BiPredicate<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, Exception> skipPredicate, LogAccessor logger, KafkaException.Level level) Seek the remaining records, optionally recovering the first.- Parameters:
thrownException
- the exception.records
- the remaining records.consumer
- the consumer.container
- the container.commitRecovered
- true to commit the recovered record offset.skipPredicate
- the skip predicate.logger
- the logger.level
- the log level for the thrown exception after handling.- Since:
- 2.5
-
seekOrRecover
public static void seekOrRecover(Exception thrownException, @Nullable List<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, boolean commitRecovered, RecoveryStrategy recovery, LogAccessor logger, KafkaException.Level level) Seek the remaining records, optionally recovering the first.- Parameters:
thrownException
- the exception.records
- the remaining records.consumer
- the consumer.container
- the container.commitRecovered
- true to commit the recovered record offset.recovery
- theRecoveryStrategy
.logger
- the logger.level
- the log level for the thrown exception after handling.- Since:
- 2.7
-
isBackoffException
Return true if the exception is aKafkaBackoffException
.- Parameters:
exception
- the exception.- Returns:
- true if it's a back off.
- Since:
- 2.7
-