Class BatchMessagingMessageListenerAdapter<K,V>
java.lang.Object
org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter<K,V>
org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter<K,V>
- Type Parameters:
K
- the key type.V
- the value type.
- All Implemented Interfaces:
BatchAcknowledgingConsumerAwareMessageListener<K,
,V> BatchMessageListener<K,
,V> ConsumerSeekAware
,GenericMessageListener<List<org.apache.kafka.clients.consumer.ConsumerRecord<K,
V>>>
public class BatchMessagingMessageListenerAdapter<K,V>
extends MessagingMessageListenerAdapter<K,V>
implements BatchAcknowledgingConsumerAwareMessageListener<K,V>
A
MessageListener
adapter that invokes a configurable HandlerAdapter
; used when the factory is
configured for the listener to receive batches of messages.
Wraps the incoming Kafka Message to Spring's Message
abstraction.
The original List<ConsumerRecord>
and
the Acknowledgment
are provided as additional arguments so that these can
be injected as method arguments if necessary.
- Since:
- 1.1
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter
MessagingMessageListenerAdapter.ReplyExpressionRoot
Nested classes/interfaces inherited from interface org.springframework.kafka.listener.ConsumerSeekAware
ConsumerSeekAware.ConsumerSeekCallback
-
Field Summary
Fields inherited from class org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter
logger, NULL_MESSAGE
-
Constructor Summary
ConstructorDescriptionBatchMessagingMessageListenerAdapter
(Object bean, Method method) Create an instance with the provided parameters.BatchMessagingMessageListenerAdapter
(Object bean, Method method, KafkaListenerErrorHandler errorHandler) Create an instance with the provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected final BatchMessageConverter
Return theBatchMessagingMessageConverter
for this listener, being able to convertMessage
.protected void
invoke
(Object records, Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, org.springframework.messaging.Message<?> messageArg) void
onMessage
(List<org.apache.kafka.clients.consumer.ConsumerRecord<K, V>> records, Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) KafkaMessageListener
entry point.void
onMessage
(org.apache.kafka.clients.consumer.ConsumerRecords<K, V> records, Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<K, V> consumer) Listener receives the originalConsumerRecords
object instead of a list ofConsumerRecord
.void
setBatchMessageConverter
(BatchMessageConverter messageConverter) Set the BatchMessageConverter.void
setBatchToRecordAdapter
(BatchToRecordAdapter<K, V> batchToRecordAdapter) Set aBatchToRecordAdapter
.protected org.springframework.messaging.Message<?>
toMessagingMessage
(List records, Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) boolean
Return true if this listener wishes to receive the originalConsumerRecords
object instead of a list ofConsumerRecord
.Methods inherited from class org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter
createMessagingErrorMessage, determineInferredType, getMessageConverter, getReplyHeadersConfigurer, getType, handleResult, invokeHandler, isConsumerRecordList, isConsumerRecords, isConversionNeeded, isMessageList, isSplitIterables, onIdleContainer, onPartitionsAssigned, onPartitionsRevoked, registerSeekCallback, sendResponse, setBeanResolver, setCorrelationHeaderName, setFallbackType, setHandlerMethod, setMessageConverter, setMessagingConverter, setReplyHeadersConfigurer, setReplyTemplate, setReplyTopic, setSplitIterables, toMessagingMessage
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.BatchAcknowledgingConsumerAwareMessageListener
onMessage
Methods inherited from interface org.springframework.kafka.listener.ConsumerSeekAware
onFirstPoll, unregisterSeekCallback
Methods inherited from interface org.springframework.kafka.listener.GenericMessageListener
onMessage, onMessage
-
Constructor Details
-
BatchMessagingMessageListenerAdapter
Create an instance with the provided parameters.- Parameters:
bean
- the listener bean.method
- the listener method.
-
BatchMessagingMessageListenerAdapter
public BatchMessagingMessageListenerAdapter(Object bean, Method method, @Nullable KafkaListenerErrorHandler errorHandler) Create an instance with the provided parameters.- Parameters:
bean
- the listener bean.method
- the listener method.errorHandler
- the error handler.
-
-
Method Details
-
setBatchMessageConverter
Set the BatchMessageConverter.- Parameters:
messageConverter
- the converter.
-
setBatchToRecordAdapter
Set aBatchToRecordAdapter
.- Parameters:
batchToRecordAdapter
- the adapter.- Since:
- 2.4.2
-
getBatchMessageConverter
Return theBatchMessagingMessageConverter
for this listener, being able to convertMessage
.- Returns:
- the
BatchMessagingMessageConverter
for this listener, being able to convertMessage
.
-
wantsPollResult
public boolean wantsPollResult()Description copied from interface:BatchMessageListener
Return true if this listener wishes to receive the originalConsumerRecords
object instead of a list ofConsumerRecord
.- Specified by:
wantsPollResult
in interfaceBatchMessageListener<K,
V> - Returns:
- true for consumer records.
-
onMessage
public void onMessage(org.apache.kafka.clients.consumer.ConsumerRecords<K, V> records, @Nullable Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<K, V> consumer) Description copied from interface:BatchMessageListener
Listener receives the originalConsumerRecords
object instead of a list ofConsumerRecord
.- Specified by:
onMessage
in interfaceBatchMessageListener<K,
V> - Parameters:
records
- the records.acknowledgment
- the acknowledgment (null if not manual acks)consumer
- the consumer.
-
onMessage
public void onMessage(List<org.apache.kafka.clients.consumer.ConsumerRecord<K, V>> records, @Nullable Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) KafkaMessageListener
entry point.Delegate the message to the target listener method, with appropriate conversion of the message argument.
- Specified by:
onMessage
in interfaceBatchAcknowledgingConsumerAwareMessageListener<K,
V> - Specified by:
onMessage
in interfaceGenericMessageListener<K>
- Parameters:
records
- the incoming list of KafkaConsumerRecord
.acknowledgment
- the acknowledgment.consumer
- the consumer.
-
invoke
protected void invoke(Object records, @Nullable Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, org.springframework.messaging.Message<?> messageArg) -
toMessagingMessage
protected org.springframework.messaging.Message<?> toMessagingMessage(List records, @Nullable Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer)
-