spring-retry icon indicating copy to clipboard operation
spring-retry copied to clipboard

Can't chose correct @Recover method

Open xytrams opened this issue 5 years ago • 4 comments

In case of multiple @Recover method, apparently only one is considered, others are ignored. Example:

@CircuitBreaker(openTimeout=1000, resetTimeout=2000, maxAttempts=2)
public Response submit(Object o) {
... retry logic with retryTemplate
}
@CircuitBreaker(openTimeout=1000, resetTimeout=2000, maxAttempts=2)
public Response query(String id) {
... retry logic with retryTemplate
}
@Recover
public Response fallbackForSubmit(Throwable e, Object o) {....}
@Recover 
public Response fallbackForQuery(Throwable e, String id) (....}

In my case fallbackForQuery is not considered as recovery method. If I comment out fallbackForSubmit recover method - than it works.

I've seen there were some changes introduced to allow to add @Retry(recoverName="recover1") in https://github.com/spring-projects/spring-retry/issues/85 , but it is not exactly my scenario since I'm not using @Retry annotation but rather retryTemplate.

Could you advise how should I proceed with my problem?

xytrams avatar Nov 12 '19 15:11 xytrams

Did you try @Retryable(recover=...) (note the spelling of both annotation name and attribute)? Or is it just that you need the @CircuitBreaker to alias that attribute before it will work? Your comment about "using retryTemplate" didn't make sense to me.

dsyer avatar Jan 20 '20 11:01 dsyer

@dsyer when will this recover parameter be available in Branch 1.2.X ?

currently I'm working with 1.2.5.RELEASE which doesn't contain this yet.

Nocturne183 avatar Mar 09 '20 14:03 Nocturne183

It's in 1.3 I think. It looks like maybe we need an alias?

dsyer avatar Mar 09 '20 15:03 dsyer

@dsyer Sorry, I completely forgot about this one. I'll try to remember from memory what was scenario (please allow some latitude - it was 2 years ago) In one of my services I had to reach out to two external calls to different clients (urls) which could be unreliable, so decision was made to annotate both of them with @CircuitBreaker. Two different @CircuitBreaker weren't the problem, but eventually I needed two different @Recover for each of them - and this couldn't be distinguished which @Recover belongs to which @CircuitBreaker. So yes, some alias or name of @CircuitBreaker with corresponding alias or name of @Recover should solve the problem.

Once again - apologies for late reply.

xytrams avatar Jun 09 '21 12:06 xytrams