概述
2019独角兽企业重金招聘Python工程师标准>>>
@Configuration
@ConditionalOnProperty(value = "spring.sleuth.feign.enabled", havingValue = "false")
@Slf4j
public class CommonHystrixConfiguration {
/**
* hystrix 超时时间
*/
static int hystrixTimeOut = 10000;
/**
* 请求超时时间
*/
static int requestTimeOut = 3000;
@Bean
public Request.Options options() {
return new Request.Options(requestTimeOut, requestTimeOut);
}
@Bean
Retryer feignRetryer() {
return new Retryer.Default(100, SECONDS.toMillis(1), 1);
}
@Bean
@Primary
public Feign.Builder feignHystrixBuilderExt(BeanFactory beanFactory) {
return HystrixFeign.builder().setterFactory(new SetterFactory() {
public HystrixCommand.Setter create(Target<?> target, Method method) {
String groupKey = target.name();
String commandKey = method.getName();
return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)).andCommandPropertiesDefaults(
HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(hystrixTimeOut)
.withCircuitBreakerSleepWindowInMilliseconds(hystrixTimeOut));
}
});
}
@Configuration
@ConditionalOnProperty(value = "spring.sleuth.feign.enabled", havingValue = "true")
@Slf4j
public class CommonTraceHystrixConfiguration {
/**
* hystrix 超时时间
*/
static int hystrixTimeOut = 10000;
/**
* 请求超时时间
*/
static int requestTimeOut = 3000;
@Bean
public Request.Options options() {
return new Request.Options(requestTimeOut, requestTimeOut);
}
@Bean
Retryer feignRetryer() {
return new Retryer.Default(100, SECONDS.toMillis(1), 1);
}
@Bean
@Primary
//@Scope("prototype")
public Feign.Builder feignTraceHystrixBuilderExt(BeanFactory beanFactory) {
return HystrixFeign.builder().setterFactory(new SetterFactory() {
public HystrixCommand.Setter create(Target<?> target, Method method) {
String groupKey = target.name();
String commandKey = method.getName();
return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)).andCommandPropertiesDefaults(
HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(hystrixTimeOut)
.withCircuitBreakerSleepWindowInMilliseconds(hystrixTimeOut));
}
}).client(new TraceFeignClient(beanFactory));
}
}
@Configurable /*单个类得*/
@Slf4j
public class ImServiceHystrixConfiguration {
@Bean
@ConditionalOnProperty(value = "spring.sleuth.feign.enabled", havingValue = "false")
public Feign.Builder feignHystrixBuilder() {
return HystrixFeign.builder().setterFactory(new SetterFactory() {
public HystrixCommand.Setter create(Target<?> target, Method method) {
String groupKey = target.name();
String commandKey = method.getName();
int time = 5000;
if (commandKey.startsWith("sys")) {
time = 1000 * 60 * 10;
}
return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))// 控制
// RemoteProductService
// 下,所有方法的Hystrix
// Configuration
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)).andCommandPropertiesDefaults(
HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(time) // 超时配置
);
}
});
}
@Bean
@ConditionalOnProperty(value = "spring.sleuth.feign.enabled", havingValue = "true")
public Feign.Builder feignTraceHystrixBuilder(BeanFactory beanFactory) {
log.info("load com.dominos.cloud.order.config.ImServiceHystrixConfiguration.feignTraceHystrixBuilder()");
return HystrixFeign.builder().setterFactory(new SetterFactory() {
public HystrixCommand.Setter create(Target<?> target, Method method) {
String groupKey = target.name();
String commandKey = method.getName();
int time = 5000;
if (commandKey.startsWith("sys")) {
time = 1000 * 60 * 10;
}
return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))// 控制
// RemoteProductService
// 下,所有方法的Hystrix
// Configuration
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)).andCommandPropertiesDefaults(
HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(time) // 超时配置
);
}
}).client(new TraceFeignClient(beanFactory));
}
@Bean
public Request.Options options() {
return new Request.Options(6000 * 100, 6000 * 100);
}
}
转载于:https://my.oschina.net/xiaominmin/blog/3048888
最后
以上就是诚心流沙为你收集整理的Hystrix 超时配置重写的全部内容,希望文章能够帮你解决Hystrix 超时配置重写所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复