How can detect last retry? #362
-
I am using Spring-retry-1.3.4, i want to detect the event before the last retry and insert logic. TestService.java@Retryable(
value = {Exception.class},
maxAttempts = 2
)
public void test1() {}
@Retryable(
value = {Exception.class},
maxAttempts = 3
)
public void test2() {}
@Retryable(
value = {Exception.class},
maxAttempts = 4
)
public void test3() {} Like this, when I set maxAttempts differently using @retryable annotation, I want to add a common logic before last attempt. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
See our original discussion: #361. Not sure what else you'd like to hear from us that has driven you to still open this discussion... |
Beta Was this translation helpful? Give feedback.
-
There is no such mechanism available. One work around would be to use a property for the max attempts, together with a label. @Value("${test3.max}") int test3Max;
...
@Retryable(
value = {Exception.class},
maxAttemptsExpression = "#{'${test3.max}'}",
label = "test3"
)
public void test3() {} ...and use the same property in your listener. The label is available in the /**
* Retry context attribute name for reporting key. Can be used for reporting purposes,
* for instance in a retry listener, to accumulate data about the performance of a
* retry.
*/
String NAME = "context.name"; |
Beta Was this translation helpful? Give feedback.
There is no such mechanism available.
One work around would be to use a property for the max attempts, together with a label.
...and use the same property in your listener.
The label is available in the
RetryContext
under theRetryContext.NAME
property.