【问题标题】:Feign Ribbon client wait and retryFeign Ribbon 客户端等待并重试
【发布时间】:2018-08-22 10:14:10
【问题描述】:

我正在使用 Feign Ribbon 客户端与服务对话。 我有一个客户端在功能区中配置 maxAutoRetries 后立即失败。假装或功能区中是否有像“等待并重试”这样的属性,它可以等待配置的时间并重试。

【问题讨论】:

    标签: netflix-feign spring-cloud-feign netflix-ribbon feign


    【解决方案1】:

    您可以为此目的定义一个Retryer Bean。

    @Configuration
    public class RetryConfiguration {
        @Bean
        public Retryer retryer() {
            // default retryer will retry 5 times waiting waiting
            // 100 ms per retry with a 1.5* back off multiplier
            return Retryer.Default();
        }
    }
    

    如果您的需求与默认不同,您可以创建自己的 Retryer 实现。

    一旦定义,当在任何Feign 调用期间抛出RetryableException 时,将使用此重试配置。您可能还需要注册一个ErrorDecoder 以确保来自您的端点的响应被正确包装:

    public class MyErrorDecoder implements ErrorDecoder {
        @Override
        public Exception decode(String methodKey, Response response) {
           // handle the error, wrap and return
           return new RetryableException(exception);
        }
    }
    
    @Bean
    public ErrorDecoder errorDecoder() {
        return new MyErrorDecoder();
    }
    

    【讨论】:

    • 重试器 bean 应该返回 new Retryer.Default();
    猜你喜欢
    • 2018-04-19
    • 1970-01-01
    • 2021-09-27
    • 2018-12-10
    • 2018-06-01
    • 2020-07-26
    • 1970-01-01
    • 2019-11-04
    • 1970-01-01
    相关资源
    最近更新 更多