Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 803
Going Bananas Avatar asked Aug 05 '14 11:08

Going Bananas


1 Answers

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) {
like image 116
Artem Bilan Avatar answered Oct 04 '22 04:10

Artem Bilan