我可以在feignClient中使用舱壁图案吗?
2、我对hystrix有一些困惑。
例如,如果我只有三个冒充客户"a","b","c"。"a“称为"b”和"c“。
我知道我可以很容易地使用带有fallback参数和一些配置的断路器:
@FeignClient(name = "b", fallback = bFallback.class)
protected interface HystrixClient {
//some methods
}
@FeignClient(name = "c", fallback = cFallback.class)
protected interface HystrixClient {
//some methods
}以另一种方式,我可以使用@HystrixCommand用如下的配置包装远程调用:
@HystrixCommand(fallbackMethod="getFallback")
public Object get(@PathVariable("id") long id) {
//...
}此外,我还可以在@HystrixCommand或application.yml中配置一些参数,也可以在application.yml中添加threadPoolKey。
Q1:我知道Hystrix包装远程调用是为了达到目的,我可以理解后一种方式,但是前者喜欢包装被叫?
我在文件中发现:
假象将所有的方法都用一个电路中断包起来。
这是否意味着FeignClient似乎在界面的每一种方法上都添加了@Hystrixcommand?
Q2:如果假装客户端"b“有三个远程调用,我如何让它们在舱壁中运行,以避免一个方法消耗所有线程?将feignClient和@HystrixCommand结合起来?他们会发生冲突吗?
因为我没有在threadPoolKey中找到像feignClient这样的参数。汽车舱壁?
Q3:如果我的hystrix配置是application.yml,那么feignClient模式和@HytirxCommand模式是否有相同的配置模式?就像这样:
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds:1000
circuitBreaker:
requestVolumeThreshold:10
...
...但是接下来的超时时间是什么?
feign:
client:
config:
feignName:
connectTimeout: 5000
readTimeout: 5000发布于 2019-09-04 08:30:53
我可以在feignClient中使用舱壁图案吗?
Java的setterFactory()方法的HystrixFeign类说:
/**
* Allows you to override hystrix properties such as thread pools and command keys.
*/
public Builder setterFactory(SetterFactory setterFactory) {
this.setterFactory = setterFactory;
return this;
}Spring默认不提供以下bean用于假装,但仍然从应用程序上下文中查找这些类型的bean来创建虚拟客户端:·Logger.Level·Retryer·ErrorDecoder·Request.Options·Collection·SetterFactory
因此,我们应该在那里创建setterFactory并指定线程池。您可以创建这样的Bean:
@Bean
public SetterFactory feignHystrixSetterFactory() {
return (target, method) -> {
String groupKey = target.name();
String commandKey = Feign.configKey(target.type(), method);
return HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey))
.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey( target.type().getSimpleName() ));
};
}但是接下来的超时时间是什么?
假装客户端超时类似于带状超时,并指定httpconnectin的属性,但您可以为不同的feignclient定义不同的超时。
feign.client.config.bar.readTimeout //this configuration will apply to bar client
feign.client.config.default.readTimeout // this configuration will apply to all feign 我是怎么找到的?如果调试应用程序并在RetryableFeignLoadBalancer类的以下代码上放置断点:
final Request.Options options;
if (configOverride != null) {
RibbonProperties ribbon = RibbonProperties.from(configOverride);
options = new Request.Options(ribbon.connectTimeout(this.connectTimeout),
ribbon.readTimeout(this.readTimeout));
}
else {
options = new Request.Options(this.connectTimeout, this.readTimeout);
}您将看到这些值将用作HTTPConection.pls的属性,请查看feign.Client类。
connection.setConnectTimeout(options.connectTimeoutMillis());
connection.setReadTimeout(options.readTimeoutMillis());https://stackoverflow.com/questions/55517451
复制相似问题