@Configuration@ConditionalOnProperty(value = "spring.sleuth.feign.enabled", havingValue = "false")@Slf4jpublic 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")@Slf4jpublic 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 /*单个类得*/@Slf4jpublic 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); }}