Search code examples
springspring-integrationspring-dsl

Spring Integration Java DSL - How to call a ServiceActivator method with retry advice


I have a Component class with a ServiceActivator method:

@Component("payloadService")
public class PayloadService {

    @Transactional
    @ServiceActivator
    @Description("Pre-check service")
    public Message<String> preCheck(Message<String> message) {
        ...
    }
}

I have a Spring Integration 4 Java DSL flow which calls the ServiceActivator's preCheck method like so:

IntegrationFlows.from("input.ch")
    .handle("payloadService", "preCheck")
    ...
    .get();

I am now trying add a retry advice to the service call (as shown here http://docs.spring.io/spring-integration/reference/htmlsingle/#retry-config) but I would like to do this in Java DSL form as documented in https://github.com/spring-projects/spring-integration-extensions/wiki/Spring-Integration-Java-DSL-Reference#dsl-and-endpoint-configuration.

However I can't quite figure out how to apply this advice in practice to my flow in DSL form. Probably struggling because I am not yet too familiar with lambdas, etc.

Could somebody give me some pointers on how to do this?

Thanks in advance, PM


Solution

  • Like this:

    ....
    
    IntegrationFlows.from("input.ch")
        .handle("payloadService", "preCheck", e -> e.advice(retryAdvice()))
        ...
        .get();
    
    ....
    
    @Bean
    public Advice retryAdvice() {
       RequestHandlerRetryAdvice advice = new RequestHandlerRetryAdvice();
       ...
       return advice;
    }
    

    From other side you can try the new annotation stuff from Spring Retry project:

    @Configuration
    @EnableIntegration
    @EnableRetry
    ....
    
    @Transactional
    @ServiceActivator
    @Retryable
    @Description("Pre-check service")
    public Message<String> preCheck(Message<String> message) {