5

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

Going Bananas
  • 2,265
  • 3
  • 43
  • 83

1 Answers1

11

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) {
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thanks Artem, I think doing the retry advice via annotations will be much better. I'll give them a go. Cheers! – Going Bananas Aug 05 '14 at 11:23
  • I am trying the annotations approach for retries but when I set @EnableRetry on my Config class, I get the following exception when I try to startup the project (using spring-boot): `Can not set org.springframework.boot.autoconfigure.web.ServerProperties field org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.properties to com.sun.proxy.$Proxy69`. Any ideas why this might be? My Main class is annotated with `@EnableAutoConfiguration`. – Going Bananas Aug 05 '14 at 12:50
  • Good catch! No ideas. Need to check. Never have used `@EnableRetry` with Boot. It may be an issue, of course. – Artem Bilan Aug 05 '14 at 13:51
  • 1
    Maybe spring-retry together with spring-boot is not quite ready for prime time just yet! For now I will use the `EndpointConfigurer` approach in the DSL flow's `.handle("payloadService", "preCheck", e -> e.advice(retryAdvice()))` call as you initially suggested. Using this approach the retry advice definitely works okay. Thanks again! – Going Bananas Aug 05 '14 at 14:38