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

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

Hystrix 超时配置重写相关推荐

  1. SpringCloud feign、hystrix、zuul超时配置

    hystrix超时配置一般需要手动配置,如果不配,接口响应稍慢就会熔断 同样,zuul也有超时配置,feign也有超时配置 zuul配置时,配置如下: hystrix: command: defaul ...

  2. ribbon基于接口配置超时_feign的ribbon超时配置和hystrix的超时配置说明

    先看下我的配置: ribbon: MaxAutoRetries: 1 #最大重试次数,当Eureka中可以找到服务,但是服务连不上时将会重试 MaxAutoRetriesNextServer: 1 # ...

  3. python接口自动化测试(五)-其它(认证代理超时配置)

    有了前面几节的介绍,基本的接口测试是可以满足了.本节一些其它的高级技巧: 一.认证 1.基本认证: # -*- coding:utf-8 -*- import requestsurl = " ...

  4. SpringCloud Hystrix超时:HystrixRuntimeException: xxx failed and no fallback available

    报错描述:Spring Boot + Spring Cloud项目,微服务之间RPC调用, 使用Feign时经常出现执行超时的情况,抛出异常如下图: com.netflix.hystrix.excep ...

  5. http各种超时配置

    httpclient–请求方浏览器 connectTimeOut:建立连接时间 三次握手 org.apache.http.conn.HttpHostConnectException: Connect ...

  6. 关于Hystrix超时机制和线程状态的测试观察和个人理解

    作者:未完成交响曲,资深Java工程师!目前在某一线互联网公司任职,架构师社区合伙人! 我们在使用Hystrix时,大部分情况下都是直接基于SpringCloud的相关注解来完成请求调用的.我们有个项 ...

  7. SpringCloud系列七:Hystrix 熔断机制(Hystrix基本配置、服务降级、HystrixDashboard服务监控、Turbine聚合监控)...

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:Hystrix 熔断机制 2.具体内容 所谓的熔断机制和日常生活中见到电路保险丝是非常相似的,当出现了问题之后,保险丝 ...

  8. Hystrix全局配置默认超时时间

  9. hystrix相关配置

    Execution相关的属性的配置 hystrix.command.default.execution.isolation.strategy 隔离策略,默认是Thread, 可选Thread| Sem ...

最新文章

  1. 在内网中使用maven_搭建私有maven仓库并在项目中使用
  2. 用Lean Pilots推动改进
  3. java8 接口调用默认方法_Java8接口里的默认方法特性
  4. HTTPS加密越来越流行,为何要加密?
  5. jpeg6 安装问题!
  6. 区分Debug版还是Relase版
  7. 【置顶】方立勋JavaWeb学习地址
  8. VS2022+.NET6+C#10,.NET开发起飞
  9. jmeter线程数并发数区别_如何确定Kafka的分区数、key和consumer线程数、以及不消费问题解决...
  10. ECS 游戏框架背景知识
  11. 「数据分析」Sqlserver中的窗口函数的精彩应用-问题篇
  12. java在线支付---01_在线支付功能的演示与概述
  13. matlab单行注释,matlab注释
  14. java靜態常量_Java靜態變量、靜態常量、靜態方法
  15. Cogs 2221. [SDOI2016 Round1] 数字配对(二分图)
  16. void main(){char str[] = “\tab\n\014\\\“;printf(“%d“,strlen(str))}
  17. docker 容器通过桥接方式绑定到宿主机无法访问另外一个docker容器
  18. (PPT)Linux服务器基础
  19. C语言编译器哪个好用,常用C语言编译器有哪些
  20. 我也撸了一个古诗词网站

热门文章

  1. 使用 spring boot 开发通用程序
  2. 数据库与操作系统时区更改
  3. spring-cloud-ribbon负载均衡
  4. C++编程思想重点笔记(上)
  5. 缺少HTML Doctype造成的样式问题
  6. Integer的自动缓存
  7. iOS webview 点击按钮返回上一页面或者返回首页
  8. 14个Xcode中常用的快捷键操作
  9. 使用kaptcha生成验证码
  10. 浅谈 sessionStorage、localStorage、cookie 的区别以及使用