Class PartitionPausingBackoffManager
- java.lang.Object
-
- org.springframework.kafka.listener.PartitionPausingBackoffManager
-
- All Implemented Interfaces:
java.util.EventListener,org.springframework.context.ApplicationListener<ListenerContainerPartitionIdleEvent>,KafkaConsumerBackoffManager
public class PartitionPausingBackoffManager extends java.lang.Object implements KafkaConsumerBackoffManager, org.springframework.context.ApplicationListener<ListenerContainerPartitionIdleEvent>
A manager that backs off consumption for a given topic if the timestamp provided is not due. Use withSeekToCurrentErrorHandlerto 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 aContainerProperties.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
Constructors Constructor Description PartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry)Constructs an instance with the providedListenerContainerRegistryand with no timing adjustment capabilities.PartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry, java.time.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, java.time.Clock clock)Creates an instance with the providedListenerContainerRegistry,KafkaConsumerTimingAdjusterandClock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddBackoff(KafkaConsumerBackoffManager.Context context, org.apache.kafka.common.TopicPartition topicPartition)voidbackOffIfNecessary(KafkaConsumerBackoffManager.Context context)Backs 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, wait
-
Methods inherited from interface org.springframework.kafka.listener.KafkaConsumerBackoffManager
createContext
-
-
-
-
Constructor Detail
-
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
public PartitionPausingBackoffManager(ListenerContainerRegistry listenerContainerRegistry)
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, java.time.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, java.time.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 Detail
-
backOffIfNecessary
public void backOffIfNecessary(KafkaConsumerBackoffManager.Context context)
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
public void onApplicationEvent(ListenerContainerPartitionIdleEvent partitionIdleEvent)
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<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)
-
-