Class KafkaBackoffAwareMessageListenerAdapter<K,V>
java.lang.Object
org.springframework.kafka.listener.adapter.AbstractDelegatingMessageListenerAdapter<MessageListener<K,V>>
org.springframework.kafka.listener.adapter.KafkaBackoffAwareMessageListenerAdapter<K,V>
- Type Parameters:
K
- the record key type.V
- the record value type.
- All Implemented Interfaces:
AcknowledgingConsumerAwareMessageListener<K,
,V> ConsumerSeekAware
,DelegatingMessageListener<MessageListener<K,
,V>> GenericMessageListener<org.apache.kafka.clients.consumer.ConsumerRecord<K,
,V>> MessageListener<K,
V>
public class KafkaBackoffAwareMessageListenerAdapter<K,V>
extends AbstractDelegatingMessageListenerAdapter<MessageListener<K,V>>
implements AcknowledgingConsumerAwareMessageListener<K,V>
A
AcknowledgingConsumerAwareMessageListener
implementation that looks for a
backoff dueTimestamp header and invokes a KafkaConsumerBackoffManager
instance
that will back off if necessary.- Since:
- 2.7
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.kafka.listener.ConsumerSeekAware
ConsumerSeekAware.ConsumerSeekCallback
-
Field Summary
Fields inherited from class org.springframework.kafka.listener.adapter.AbstractDelegatingMessageListenerAdapter
delegate, delegateType, logger
-
Constructor Summary
ConstructorDescriptionKafkaBackoffAwareMessageListenerAdapter
(MessageListener<K, V> delegate, KafkaConsumerBackoffManager kafkaConsumerBackoffManager, String listenerId, String backoffTimestampHeader, Clock clock) The configuration for this listener adapter.KafkaBackoffAwareMessageListenerAdapter
(MessageListener<K, V> adapter, KafkaConsumerBackoffManager kafkaConsumerBackoffManager, String listenerId, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked with data from kafka.void
onMessage
(org.apache.kafka.clients.consumer.ConsumerRecord<K, V> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) Invoked with data from kafka and provides access to theConsumer
.void
onMessage
(org.apache.kafka.clients.consumer.ConsumerRecord<K, V> data, Acknowledgment acknowledgment) Invoked with data from kafka.void
onMessage
(org.apache.kafka.clients.consumer.ConsumerRecord<K, V> consumerRecord, Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) Invoked with data from kafka and provides access to theConsumer
.Methods inherited from class org.springframework.kafka.listener.adapter.AbstractDelegatingMessageListenerAdapter
getDelegate, onIdleContainer, onPartitionsAssigned, onPartitionsRevoked, registerSeekCallback
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.ConsumerSeekAware
onFirstPoll, unregisterSeekCallback
-
Constructor Details
-
KafkaBackoffAwareMessageListenerAdapter
public KafkaBackoffAwareMessageListenerAdapter(MessageListener<K, V> delegate, KafkaConsumerBackoffManager kafkaConsumerBackoffManager, String listenerId, String backoffTimestampHeader, Clock clock) The configuration for this listener adapter.- Parameters:
delegate
- the MessageListener instance that will handle the messages.kafkaConsumerBackoffManager
- the manager that will handle the back off.listenerId
- the id of the listener container associated to this adapter.backoffTimestampHeader
- the header name that will be looked up in the incoming record to acquire the timestamp.clock
- the clock instance that will be used to timestamp the exception throwing.- Since:
- 2.7
-
KafkaBackoffAwareMessageListenerAdapter
public KafkaBackoffAwareMessageListenerAdapter(MessageListener<K, V> adapter, KafkaConsumerBackoffManager kafkaConsumerBackoffManager, String listenerId, Clock clock) throws KafkaBackoffException- Throws:
KafkaBackoffException
-
-
Method Details
-
onMessage
public void onMessage(org.apache.kafka.clients.consumer.ConsumerRecord<K, V> consumerRecord, @Nullable Acknowledgment acknowledgment, @Nullable org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) Description copied from interface:GenericMessageListener
Invoked with data from kafka and provides access to theConsumer
. The default implementation throwsUnsupportedOperationException
.- Specified by:
onMessage
in interfaceAcknowledgingConsumerAwareMessageListener<K,
V> - Specified by:
onMessage
in interfaceGenericMessageListener<K>
- Parameters:
consumerRecord
- the data to be processed.acknowledgment
- the acknowledgment.consumer
- the consumer.
-
onMessage
Description copied from interface:AcknowledgingConsumerAwareMessageListener
Invoked with data from kafka. Containers should never call this since it they will detect that we are a consumer aware acknowledging listener.- Specified by:
onMessage
in interfaceAcknowledgingConsumerAwareMessageListener<K,
V> - Specified by:
onMessage
in interfaceGenericMessageListener<K>
- Parameters:
data
- the data to be processed.
-
onMessage
public void onMessage(org.apache.kafka.clients.consumer.ConsumerRecord<K, V> data, Acknowledgment acknowledgment) Description copied from interface:GenericMessageListener
Invoked with data from kafka. The default implementation throwsUnsupportedOperationException
.- Specified by:
onMessage
in interfaceGenericMessageListener<K>
- Parameters:
data
- the data to be processed.acknowledgment
- the acknowledgment.
-
onMessage
public void onMessage(org.apache.kafka.clients.consumer.ConsumerRecord<K, V> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) Description copied from interface:GenericMessageListener
Invoked with data from kafka and provides access to theConsumer
. The default implementation throwsUnsupportedOperationException
.- Specified by:
onMessage
in interfaceGenericMessageListener<K>
- Parameters:
data
- the data to be processed.consumer
- the consumer.
-