Skip to content
Advertisement

Use batch mode for dynamic listener

I am using a dynamic message listener. An example is shown below. I want to convert this to a batch listener (consume multiple messages at once).

public class RetryMessageListener
    implements AcknowledgingConsumerAwareMessageListener<String, String> {

    @Override
    public void onMessage(ConsumerRecord<String, String> consumerRecord, Acknowledgement acknowledgement, Consumer<?, ?> consumer) {

    }

}

Is there a way to convert this, so that the listener consumes a list of consumer records? I am using spring-kafka with spring-boot.

Thanks in advance

Advertisement

Answer

Implement BatchAcknowledgingConsumerAwareMessageListener instead.

/**
 * Listener for handling a batch of incoming Kafka messages, propagating an acknowledgment
 * handle that recipients can invoke when the message has been processed. The list is
 * created from the consumer records object returned by a poll. Access to the
 * {@link Consumer} is provided.
 *
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement