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
- Author:
- Stephane Nicoll, Gary Russell, Artem Bilan, Venil Noronha
-
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.protected voidinvoke(Object records, Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Message<?> messageArg) 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.protected 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
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, 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
-
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.
-
invoke
protected void invoke(Object records, @Nullable Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, Message<?> messageArg) -
toMessagingMessage
protected Message<?> toMessagingMessage(List records, @Nullable Acknowledgment acknowledgment, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer)
-