Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access current retry attempt when using @Retryable approach

I am using annotation based approach - @Retryable to do retry in spring boot application.

@Retryable(value = {DataAccessException.class, JpaSystemException.class}, maxAttempts = Integer.MAX_VALUE, backoff = @Backoff(delay = 30000))

What I want to do is, everytime it retries I want to access its current retry attempt.

I tried doing this using Java Reflection -

Retryable retryable = mth.getAnnotation(Retryable.class);

But using this I am not getting the current retry attempt. It just gives the details which are been added to the @Retryable attribute like value, maxAttempts, Backoff details

Any idea on this? Help is highly appreciated.

like image 535
Saurabh Deshpande Avatar asked Mar 05 '23 03:03

Saurabh Deshpande


1 Answers

You can't access the template, unless you wire up your own interceptor and provide it to the @Retryable in the interceptor property.

You can, however access the count within the @Retryable method using

int retry = RetrySynchronizationManager.getContext().getRetryCount();
like image 124
Gary Russell Avatar answered Mar 08 '23 23:03

Gary Russell