Skip to content

Add support for DLQ error handling within functional programming model #1729

Closed
@boonware

Description

@boonware

I'm been reading available documentation and I am very confused about the correct approach to get an error topic working when using the Kafka binder.

The current documentation states that the property spring.cloud.stream.bindings.error.destination can be used to configure a global error topic, but this support appears to have been removed in this commit.

I have also tried to implement using properties for the Kafka binder specifically; the code below demonstrates my attempt, including the configuration.

My Maven BOM is org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR1 and my dependencies are:

    org.springframework.boot:spring-boot-starter-web
    org.springframework.cloud:spring-cloud-stream
    org.springframework.cloud:spring-cloud-starter-stream-kafka

It would be great if it could be clarified how exactly a global error topic can be set up. So far, with the code below, I can see the message being handled multiple times via retries, but nothing is sent to the error topic (DLQ) that I have configured.

@SpringBootApplication
@EnableBinding(Processor.class)
public class Application {

    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
@Configuration
public class AppConfig {

    @Bean
    public ServiceImpl service() {
        return new ServiceImpl();
    }

    @Bean
    public Function<String, String> execute(ServiceImpl service) {
        return service::doBusinessLogic;
    }
}
public class ServiceImpl {

    public String doBusinessLogic(String message) {
        System.out.println("Handling message");
        if (message.startsWith("foo")) {
            throw new RuntimeException("This is a test");
        }
        return message;
    }

}
spring:
  cloud:
    stream:
      kafka:
        binder:
          brokers: localhost:9091
          autoCreateTopics: false
        bindings:
          input:
            consumer:
              enableDlq: true
              dlqName: myErrorTopic

      bindings:
        input:
          destination: myInputTopic
          group: myConsumerGroup
        output:
          destination: myOutputTopic

      function:
        definition: execute

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions