Issue
I am using spring-retry with configurations loaded from https://launchdarkly.com/. We have this feature flag service where I can change configurations like maxAttempts
and interval
from the feature flag. However, spring-retry doesn't react to it. Is there any way to detect these new configurations?
Following is the example:
This is retry method:
@Retryable(
exceptionExpression = "#{@config.isInExceptionListForReExecution(#root)}",
maxAttemptsExpression = "#{@config.getMaxAttemptsForReExecution()}",
backoff = @Backoff(delayExpression = "#{@config.getIntervalBetweenReExecution()}"))
@Transactional(value = "transactionManagerDC")
public CustomRule executeWithRetry(CustomRule customRule, SyncObject oldObject, SyncObject newObject, CustomRuleType type, Map<String, Object> kafkaEvent, Boolean strictValidation) {
int retry = RetrySynchronizationManager.getContext().getRetryCount();
logger.info("Start executing process [{}] for object [{}] with Retry [{}]", customRule.getId(), objectId, retry);
}
And this is config
bean, which injects feature flag service and reads the value from flags.
@Service
class Config {
@Inject
private FeatureFlagService featureFlagService;
public boolean isInExceptionListForReExecution(Object exception1) {
String stringFlag = featureFlagService.getStringFlag("exceptionlist");
if (!stringFlag.contains(exception1.toString())) {
return true;
}
return false;
}
public int getMaxAttemptsForReExecution() {
int maxAttempts = featureFlagService.getIntFlag("maxAttempts");
return maxAttempts;
}
public int getIntervalBetweenReExecution() {
int interval = featureFlagService.getIntFlag("interval");
return interval;
}
}
As you can see config
bean will retrieve all configs from flags. Now, the first time what configs retrieve will be staying. If I change config it will be not considered for attempts and inteval. How to detect this change? or application needs to be restarted for that.
Solution
The configuration expressions are only evaluated once, during context initialization.
There is an open new feature request to evaluate them at runtime.
https://github.com/spring-projects/spring-retry/issues/184
Answered By - Gary Russell