0

I have a Spring Integration app with multiple endpoint that process the same data in different ways.

They all have identical '@Recover' methods which has become boilerplate and seems fragile.

Can you you centralize the @Recover method (e.g. in a standalone class) and/or can you specify how to find this @Recover annotated method?

user1016765
  • 2,935
  • 2
  • 32
  • 48

1 Answers1

1

It's not clear why would one use a @Retryable in Spring Integration when there is that RequestHandlerRetryAdvice: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#message-handler-advice-chain...

Anyway see this option on the @Retryable:

/**
 * Retry interceptor bean name to be applied for retryable method. Is mutually
 * exclusive with other attributes.
 * @return the retry interceptor bean name
 */
String interceptor() default "";

So, instead of @Recover method you provide your own:

    @Bean
    public MethodInterceptor retryInterceptor() {
        return RetryInterceptorBuilder.stateless()
                     .maxAttempts(...)
                     .recoverer(...)
                     .build();
    }
  ...
  @Retryable(interceptor = "retryInterceptor")
    public void service() {
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Reason I'm not using RequestHandlerRetryAdvice is I couldn't see an annotation/way to integrate without XML - my MessagingGateway/Gateway and ServiceActivator are simple annotations to avoid bloated XML and Retryable works fine for my use-case (simply network glitches as endpoints integrate with FTP, SharePoint etc. just wanted to centralise recording failures)..... Unless there's another approach you could recommend. Overall I like that the interceptor is explicit in your answer; means other devs can figure it out even if they're not familiar with Spring Integration. – user1016765 May 11 '20 at 19:08
  • See `@ServiceActivator` `adviceChain`. That's where you can configure that `RequestHandlerRetryAdvice`. – Artem Bilan May 11 '20 at 19:10