首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在上下文初始化后更新spring重试属性

如何在上下文初始化后更新spring重试属性
EN

Stack Overflow用户
提问于 2021-09-09 12:02:58
回答 1查看 90关注 0票数 0

我正在使用spring-retry和从https://launchdarkly.com/加载的配置。我们有这个功能标志服务,我可以在其中更改功能标志的配置,如maxAttemptsinterval。但是,spring-retry不会对此做出反应。有没有办法检测这些新的配置?

示例如下:

这是重试方法:

代码语言:javascript
复制
@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);
        
    }

这是config bean,它注入特性标志服务并从标志中读取值。

代码语言:javascript
复制
@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;
    }

}

正如您所看到的,config bean将从标志中检索所有配置。现在,第一次configs检索的内容将被保留。如果我更改了配置,则不会考虑尝试和积分。如何检测这种变化?或者需要为此重新启动应用程序。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-09 14:07:32

在上下文初始化期间,配置表达式只计算一次。

有一个开放的新功能请求,用于在运行时对其进行评估。

https://github.com/spring-projects/spring-retry/issues/184

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69117814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档