问题描述
Spring Cloud doc 说:
The Spring Cloud doc says:
- 那很好,但是如何配置Hystrix选项以忽略某些异常?我有一个
ErrorDecoder
实现,它将HTTP状态代码映射到异常.如果我在方法上加上@HystrixCommand
,Feign会尊重吗? - 我们的要求是记录有关对依赖项进行的每个HTTP调用的各种详细信息.目前,我有一个装饰的
RestTemplate
可以做到这一点.根据我在代码中看到的以及基于Dave Syer的回答此处,Feign确实做到了不要使用RestTemplate
.那么我如何满足日志记录要求呢?界面feign.Client
看起来很有希望,尽管我不确定是否要使用它.
- 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? - 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 aRestTemplate
. So how do I meet the logging requirement? The interfacefeign.Client
looks promising, although I'm not entirely sure if that's the one to use.
推荐答案
就像@spencergibb所说,Feign现在不支持忽略异常,为此我打开了增强请求.至于第二个要求,RequestInterceptor
不会削减它,因为我需要响应时间,而RequestInterceptor
无法访问该响应时间.我最终实现了feign.Client
并记录了execute
方法所花费的时间.大多数代码取自feign.Client.Default
,太糟糕了以至于该类不是为扩展而设计的.然后,在FeignBuilder
中使用我的自定义客户端,如下所示:
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客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!