2019独角兽企业重金招聘Python工程师标准>>>
@Configuration
@ConditionalOnProperty(value = "spring.sleuth.feign.enabled", havingValue = "false")
@Slf4j
public class CommonHystrixConfiguration {/*** hystrix 超时时间*/static int hystrixTimeOut = 10000;/*** 请求超时时间*/static int requestTimeOut = 3000;@Beanpublic Request.Options options() {return new Request.Options(requestTimeOut, requestTimeOut);}@BeanRetryer feignRetryer() {return new Retryer.Default(100, SECONDS.toMillis(1), 1);}@Bean@Primarypublic 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;@Beanpublic Request.Options options() {return new Request.Options(requestTimeOut, requestTimeOut);}@BeanRetryer 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));}@Beanpublic Request.Options options() {return new Request.Options(6000 * 100, 6000 * 100);}}