0

I have configure retries and dead letter queue in spring cloud stream kafka and all are working as expected. But here is a scenario when message failed and all retries done catch the exception only on last retry then set the failure reason in database from exception.getMessage() and push to dlq.

Application.yml

spring:
  cloud:
    stream:
      bindings:
        input:
          group: practice-kafka
          destination: practice-kafka
          consumer:
            default-retryable: false
            max-attempts: 4
            back-off-multiplier: 1.0
            back-off-initial-interval: 30000
            back-off-max-interval: 30000
      kafka:
        bindings:
          input:
            consumer:
              enable-dlq: true
              dlq-name: dlq-topic
              dlq-partitions: 1
        binder:
          auto-create-topics: true

Mesage Listener

@StreamListener("input")
public void consumeMessage(MessagePayload payload) {
   try {
      logger.info("message received {}",payload);
      operationService.process(payload);
      logger.info("service executed");
   } catch (Exception e) {
      payload.setFailure(e.getMessage);
      payloadRepo.save(payload)
      throw e
   }

}

here i want to catch the exception and set failure cause after all retries done but it is cating and saving the exception after every retry.

0 Answers0