1

I have spring cloud stream application with kafka binder that consumes and send messages. In application i configure custom error handler with retry policy, and add not retryable exception to handler. Configuration exaple:

@Bean
public ListenerContainerCustomizer<AbstractMessageListenerContainer<?, ?>> customizer(
    SeekToCurrentErrorHandler customErrorHandler
) {
    return (((container, destinationName, group) -> {
        container.setErrorHandler(customErrorHandler);
    }));
}

@Bean
public SeekToCurrentErrorHandler customErrorHandler() {
    var errorHandler = new SeekToCurrentErrorHandler(
        (consumerRecord, e) -> log.error("Got exception skip record record: {}", consumerRecord, e),
        new FixedBackOff(1000L, 10)
    );
    errorHandler.addNotRetryableException(App.MyCustomException.class);
    return errorHandler;
}

But i see, that if exception throws, than application retry to process message 3 times. Expected behaveor - will not repeat to consume messages if App.MyCustomException.class throws. How to configure retry policy for spring cloud stream kafka binder application?

Code exaple here: github

Run test for reproduce issue.

Vichukano
  • 99
  • 8

1 Answers1

1

The customizations you provide are for the container-level error handler. Binder has a different retrying mechanism. You can add the following to your configuration to ensure that the record is not re-tried when the exception occurs.

spring.cloud.stream:
    bindings:
      processor-in-0:
        ...
        consumer:
          retryableExceptions:
            ru.vichukano.kafka.binder.retry.App.MyCustomException: false

When I tried that, I didn't see the message being re-delivered.

Here are some explanations for this.

sobychacko
  • 5,099
  • 15
  • 26
  • thank you, how can prevent to add to `dlq` too ? i need when i face with specific exception, completely ignore that. is this possible now? – Amir Azizkhani Jul 24 '22 at 05:29
  • 1
    I am not sure if I fully understand the question. Are you asking for not sending the record due to a particular exception to DLQ at all? If so, I don't think that is supported in the binder. Please create an issue in Spring Cloud Stream, and we can take a look. – sobychacko Jul 25 '22 at 16:27
  • Is it possible to set this value commonly for all bindings? – Karthik Apr 28 '23 at 14:53
  • Did you check the `default` property setting? – sobychacko Apr 28 '23 at 16:55