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
  • Constructor Details

    • BatchMessagingMessageListenerAdapter

      public BatchMessagingMessageListenerAdapter(Object bean, Method method)
      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

      public void setBatchMessageConverter(BatchMessageConverter messageConverter)
      Set the BatchMessageConverter.
      Parameters:
      messageConverter - the converter.
    • setBatchToRecordAdapter

      public void setBatchToRecordAdapter(BatchToRecordAdapter<K,V> batchToRecordAdapter)
      Parameters:
      batchToRecordAdapter - the adapter.
      Since:
      2.4.2
    • getBatchMessageConverter

      protected final BatchMessageConverter getBatchMessageConverter()
      Return the BatchMessagingMessageConverter for this listener, being able to convert Message.
      Returns:
      the BatchMessagingMessageConverter for this listener, being able to convert Message.
    • wantsPollResult

      public boolean wantsPollResult()
      Description copied from interface: BatchMessageListener
      Return true if this listener wishes to receive the original ConsumerRecords object instead of a list of ConsumerRecord.
      Specified by:
      wantsPollResult in interface BatchMessageListener<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 original ConsumerRecords object instead of a list of ConsumerRecord.
      Specified by:
      onMessage in interface BatchMessageListener<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)
      Kafka MessageListener entry point.

      Delegate the message to the target listener method, with appropriate conversion of the message argument.

      Specified by:
      onMessage in interface BatchAcknowledgingConsumerAwareMessageListener<K,V>
      Specified by:
      onMessage in interface GenericMessageListener<K>
      Parameters:
      records - the incoming list of Kafka ConsumerRecord.
      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)