如何微调Spring Cloud Feign客户端? [英] How to fine-tune the Spring Cloud Feign client?

查看:163
本文介绍了如何微调Spring Cloud Feign客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring Cloud doc 说:

The Spring Cloud doc says:

如果Hystrix在类路径上,默认情况下Feign将包装所有方法 用断路器.

If Hystrix is on the classpath, by default Feign will wrap all methods with a circuit breaker.

  1. 那很好,但是如何配置Hystrix选项以忽略某些异常?我有一个ErrorDecoder实现,它将HTTP状态代码映射到异常.如果我在方法上加上@HystrixCommand,Feign会尊重吗?
  2. 我们的要求是记录有关对依赖项进行的每个HTTP调用的各种详细信息.目前,我有一个装饰的RestTemplate可以做到这一点.根据我在代码中看到的以及基于Dave Syer的回答此处,Feign确实做到了不要使用RestTemplate.那么我如何满足日志记录要求呢?界面feign.Client看起来很有希望,尽管我不确定是否要使用它.
  1. That's good but how do I configure the Hystrix options to ignore certain exceptions? I've an ErrorDecoder implementation that maps HTTP status code to exceptions. If I put @HystrixCommand on the method, does Feign honor that?
  2. Our requirement is to log various details about every HTTP call made out to dependencies. Currently I've a decorated RestTemplate that does this. From what I see in the code and based on Dave Syer's answer here, Feign does't use a RestTemplate. So how do I meet the logging requirement? The interface feign.Client looks promising, although I'm not entirely sure if that's the one to use.

推荐答案

就像@spencergibb所说,Feign现在不支持忽略异常,为此我打开了

Like @spencergibb said, Feign doesn't support ignoring exception now, for which I opened an enhancement request. As for my second requirement, a RequestInterceptor doesn't cut it because I need the response time, which the RequestInterceptor doesn't have access to. I ended up implementing the feign.Client and logging the time taken by the execute method. Most of the code is taken from feign.Client.Default, too bad that that class is not designed for extension. I then use my custom client in a FeignBuilder as follows:

@Bean
@Scope(SCOPE_PROTOTYPE)
public Feign.Builder feignBuilder() {
    return HystrixFeign.builder()
            .client(loggingEnabledFeignClient());
}

@Bean
Client loggingEnabledFeignClient() {
    return new LoggingEnabledFeignClient();
}

这篇关于如何微调Spring Cloud Feign客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆