Class BatchMessagingMessageListenerAdapter<K,V>
- Type Parameters:
K- the key type.V- the value type.
- All Implemented Interfaces:
AsyncRepliesAware,BatchAcknowledgingConsumerAwareMessageListener<K,,V> BatchMessageListener<K,,V> ConsumerSeekAware,GenericMessageListener<List<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>>>
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.ReplyExpressionRootNested 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
ConstructorsConstructorDescriptionBatchMessagingMessageListenerAdapter(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 BatchMessageConverterReturn theBatchMessagingMessageConverterfor this listener, being able to convertMessage.voidonMessage(List<org.apache.kafka.clients.consumer.ConsumerRecord<K, V>> records, Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) KafkaMessageListenerentry point.voidonMessage(org.apache.kafka.clients.consumer.ConsumerRecords<K, V> records, Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<K, V> consumer) Listener receives the originalConsumerRecordsobject instead of a list ofConsumerRecord.voidsetBatchMessageConverter(BatchMessageConverter messageConverter) Set the BatchMessageConverter.voidsetBatchToRecordAdapter(BatchToRecordAdapter<K, V> batchToRecordAdapter) Set aBatchToRecordAdapter.voidsetMessagingConverter(org.springframework.messaging.converter.SmartMessageConverter messageConverter) Set theSmartMessageConverterto use with the batch message converter.protected org.springframework.messaging.Message<?>toMessagingMessage(List records, Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) booleanReturn true if this listener wishes to receive the originalConsumerRecordsobject instead of a list ofConsumerRecord.Methods inherited from class org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter
acknowledge, asyncFailure, asyncSuccess, createMessagingErrorMessage, determineInferredType, getMessageConverter, getReplyHeadersConfigurer, getType, handleException, handleResult, invoke, invokeHandler, isAsyncReplies, isConsumerRecordList, isConsumerRecords, isConversionNeeded, isMessageList, isSplitIterables, onIdleContainer, onPartitionsAssigned, onPartitionsRevoked, registerSeekCallback, sendResponse, setBeanResolver, setCallbackForAsyncFailure, setCorrelationHeaderName, setFallbackType, setHandlerMethod, setMessageConverter, setObservationRegistry, setReplyHeadersConfigurer, setReplyTemplate, setReplyTopic, setSplitIterables, toMessagingMessageMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.kafka.listener.BatchAcknowledgingConsumerAwareMessageListener
onMessageMethods inherited from interface org.springframework.kafka.listener.ConsumerSeekAware
onFirstPoll, unregisterSeekCallbackMethods 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
-
setMessagingConverter
public void setMessagingConverter(org.springframework.messaging.converter.SmartMessageConverter messageConverter) Set theSmartMessageConverterto use with the batch message converter.When a
SmartMessageConverteris configured via@KafkaListener(contentTypeConverter = "..."), this method ensures it is properly propagated to the batch converter's record converter for message conversion in batch listeners.This method cannot be called after
setBatchMessageConverter(BatchMessageConverter)as it would cause a mutation of the internalbatchMessageConverter. Instead, theSmartMessageConverterhas to be provided on the externalBatchMessageConverter. SinceBatchMessagingMessageConverternow always has a defaultMessagingMessageConverter, users can configure the converter via the annotation without needing to set it on the factory.- Overrides:
setMessagingConverterin classMessagingMessageListenerAdapter<K,V> - Parameters:
messageConverter- the converter to set
-
getBatchMessageConverter
Return theBatchMessagingMessageConverterfor this listener, being able to convertMessage.- Returns:
- the
BatchMessagingMessageConverterfor this listener, being able to convertMessage.
-
wantsPollResult
public boolean wantsPollResult()Description copied from interface:BatchMessageListenerReturn true if this listener wishes to receive the originalConsumerRecordsobject instead of a list ofConsumerRecord.- Specified by:
wantsPollResultin 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:BatchMessageListenerListener receives the originalConsumerRecordsobject instead of a list ofConsumerRecord.- Specified by:
onMessagein 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) KafkaMessageListenerentry point.Delegate the message to the target listener method, with appropriate conversion of the message argument.
- Specified by:
onMessagein interfaceBatchAcknowledgingConsumerAwareMessageListener<K,V> - Specified by:
onMessagein interfaceGenericMessageListener<K>- Parameters:
records- the incoming list of KafkaConsumerRecord.acknowledgment- the acknowledgment.consumer- the consumer.
-
toMessagingMessage
protected org.springframework.messaging.Message<?> toMessagingMessage(List records, @Nullable Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer)
-