I have a spring boot application and i am trying to create a Kafka retry listener wherein, based of the exception type i need to change the retry attempts.
For example:
If exception type is A then the retry attempts should be 5
If exception type is B then the retry attempts should be 10
Can anyone recommend how do to this in Spring Kafka?
Following is my ListenerFactory. I am using SeekToCurrentErrorHandler
Bean
public ConcurrentKafkaListenerContainerFactory<String, test> retryListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, test> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
factory.getContainerProperties().setAckMode(AckMode.MANUAL_IMMEDIATE);
SeekToCurrentErrorHandler errorHandler = new SeekToCurrentErrorHandler((record, exception) -> {
System.out.println(
"RetryPolicy** limit has been exceeded! You should really handle this better." + record.key());
}, new FixedBackOff(0L, 3L));
errorHandler.addNotRetryableException(IllegalArgumentException.class);
errorHandler.setCommitRecovered(true);
factory.setErrorHandler(errorHandler);
// to keep the consumers alive the failure gets reported to broker so that
// consumers remain alive
factory.setStatefulRetry(true);
factory.setConcurrency(2);
return factory;
}