Class PartitionPausingBackoffManager
java.lang.Object
org.springframework.kafka.listener.PartitionPausingBackoffManager
- All Implemented Interfaces:
EventListener,ApplicationListener<ListenerContainerPartitionIdleEvent>,KafkaConsumerBackoffManager
public class PartitionPausingBackoffManager
extends Object
implements KafkaConsumerBackoffManager, ApplicationListener<ListenerContainerPartitionIdleEvent>
A manager that backs off consumption for a given topic if the timestamp provided is not
due. Use with
SeekToCurrentErrorHandler to guarantee that the message is read
again after partition consumption is resumed (or seek it manually by other means).
It's also necessary to set a ContainerProperties.setIdlePartitionEventInterval(Long)
so the Manager can resume the partition consumption.
Note that when a record backs off the partition consumption gets paused for
approximately that amount of time, so you must have a fixed backoff value per partition.- Since:
- 2.7
- Author:
- Tomaz Fernandes, Gary Russell
- See Also:
-
SeekToCurrentErrorHandler
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.kafka.listener.KafkaConsumerBackoffManager
KafkaConsumerBackoffManager.Context -
Constructor Summary
ConstructorsConstructorDescriptionPartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry) Constructs an instance with the providedListenerContainerRegistryand with no timing adjustment capabilities.PartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry, Clock clock) Creates an instance with the providedListenerContainerRegistryandClock, with no timing adjustment capabilities.PartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry, KafkaConsumerTimingAdjuster kafkaConsumerTimingAdjuster) Constructs an instance with the providedListenerContainerRegistryandKafkaConsumerTimingAdjuster.PartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry, KafkaConsumerTimingAdjuster kafkaConsumerTimingAdjuster, Clock clock) Creates an instance with the providedListenerContainerRegistry,KafkaConsumerTimingAdjusterandClock. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddBackoff(KafkaConsumerBackoffManager.Context context, org.apache.kafka.common.TopicPartition topicPartition) voidBacks off if the current time is before the dueTimestamp provided in theKafkaConsumerBackoffManager.Contextobject.protected KafkaConsumerBackoffManager.ContextgetBackOffContext(org.apache.kafka.common.TopicPartition topicPartition) voidonApplicationEvent(ListenerContainerPartitionIdleEvent partitionIdleEvent) protected voidremoveBackoff(org.apache.kafka.common.TopicPartition topicPartition) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.kafka.listener.KafkaConsumerBackoffManager
createContext
-
Constructor Details
-
PartitionPausingBackoffManager
public PartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry, KafkaConsumerTimingAdjuster kafkaConsumerTimingAdjuster) Constructs an instance with the providedListenerContainerRegistryandKafkaConsumerTimingAdjuster. The ListenerContainerRegistry is used to fetch theMessageListenerContainerthat will be backed off / resumed. The KafkaConsumerTimingAdjuster is used to make timing adjustments in the message consumption so that it processes the message closer to its due time rather than later.- Parameters:
listenerContainerRegistry- the listenerContainerRegistry to use.kafkaConsumerTimingAdjuster- the kafkaConsumerTimingAdjuster to use.
-
PartitionPausingBackoffManager
Constructs an instance with the providedListenerContainerRegistryand with no timing adjustment capabilities. The ListenerContainerRegistry is used to fetch theMessageListenerContainerthat will be backed off / resumed.- Parameters:
listenerContainerRegistry- the listenerContainerRegistry to use.
-
PartitionPausingBackoffManager
public PartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry, KafkaConsumerTimingAdjuster kafkaConsumerTimingAdjuster, Clock clock) Creates an instance with the providedListenerContainerRegistry,KafkaConsumerTimingAdjusterandClock.- Parameters:
listenerContainerRegistry- the listenerContainerRegistry to use.kafkaConsumerTimingAdjuster- the kafkaConsumerTimingAdjuster to use.clock- the clock to use.
-
PartitionPausingBackoffManager
public PartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry, Clock clock) Creates an instance with the providedListenerContainerRegistryandClock, with no timing adjustment capabilities.- Parameters:
listenerContainerRegistry- the listenerContainerRegistry to use.clock- the clock to use.
-
-
Method Details
-
backOffIfNecessary
Backs off if the current time is before the dueTimestamp provided in theKafkaConsumerBackoffManager.Contextobject.- Specified by:
backOffIfNecessaryin interfaceKafkaConsumerBackoffManager- Parameters:
context- the back off context for this execution.
-
onApplicationEvent
- Specified by:
onApplicationEventin interfaceApplicationListener<ListenerContainerPartitionIdleEvent>
-
addBackoff
protected void addBackoff(KafkaConsumerBackoffManager.Context context, org.apache.kafka.common.TopicPartition topicPartition) -
getBackOffContext
@Nullable protected KafkaConsumerBackoffManager.Context getBackOffContext(org.apache.kafka.common.TopicPartition topicPartition) -
removeBackoff
protected void removeBackoff(org.apache.kafka.common.TopicPartition topicPartition)
-