博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hystrix 超时配置重写
阅读量:6984 次
发布时间:2019-06-27

本文共 4479 字,大约阅读时间需要 14 分钟。

hot3.png

@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); }}

 

转载于:https://my.oschina.net/xiaominmin/blog/3048888

你可能感兴趣的文章
ubuntu下安装加装DNS
查看>>
线性回归——最小二乘法_实例(二)
查看>>
POJ2866:Who Gets the Most Candies?(线段树 + 反素数 + 约瑟夫环)
查看>>
微信支付开发(12) 认清微信支付v2和v3
查看>>
k8s学习笔记之三:k8s快速入门
查看>>
SpringBoot慕课学习-SpringBoot开发常用技术整合
查看>>
即将毕业的一些感想
查看>>
iframe 解决跨域问题
查看>>
The existing index has no NexusIndexer descriptor
查看>>
界面收缩和扩展
查看>>
Selenium学习(14) 判断元素expected_conditions
查看>>
Linux命令之tcpdump
查看>>
(更新)Java + 腾讯企业邮箱 + javamail + SSL 发送邮件
查看>>
组合数据类型综合练习
查看>>
php回调函数callback函数实例
查看>>
示波器测量电源的纹波
查看>>
自定义ListBox,实现单多选切换(复选框)
查看>>
软件测试2019:第八次作业
查看>>
Centos下安装FTP并进行虚拟用户访问方式配置
查看>>
python day09
查看>>