由于客户端请求服务端方法时,服务端方法响应超过1秒将会触发降级,所以我们可以配置Hystrix默认的超时配置

如果我们没有配置默认的超时时间,Hystrix将取default_executionTimeoutInMilliseconds作为默认超时时间

this.executionTimeoutInMilliseconds = getProperty(propertyPrefix, key, "execution.isolation.thread.timeoutInMilliseconds", builder.getExecutionIsolationThreadTimeoutInMilliseconds(), default_executionTimeoutInMilliseconds)

1.代码中修改默认超时配置(改为3秒):

@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
})
public String serverMethod() {
  return null;
}
2.application.properties中设置默认超时时间:
1.默认:(方法上记得要加上@HystrixCommand,否则无效):
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=3000 2.配置具体方法的超时时间
hystrix.command.serverMethod.execution.isolation.thread.timeoutInMilliseconds=3000

3.启动类:

package com.wangfajun;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; //@SpringBootApplication
//@EnableDiscoveryClient
//@EnableCircuitBreaker //开启断路器
@SpringCloudApplication
public class FajunClientTestApplication { public static void main(String[] args) {
SpringApplication.run(FajunClientTestApplication.class, args);
}
}

4.pom:

<!--hystrix-->
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>

最新文章

  1. jdk8飞行记录器配置
  2. Windows 之 删除文件出现“该项目不在请确认该项目的位置”
  3. 设置transparent是否多此一举
  4. YCbCr
  5. Delphi 记事本 TMemo(5篇)
  6. 11g的alert日志路径
  7. poj1163The Triangle(简单DP)
  8. 第四章——SQLServer2008-2012资源及性能监控(1)
  9. linux centos7 安装redis
  10. websocket(三) 进阶!netty框架实现websocket达到高并发
  11. 从初识Maven到使用Maven进行依赖管理和项目构建
  12. Object.defineProperty实现数据绑定
  13. 解决mongodb的安装mongod命令不是内部或外部命令
  14. 2、CentOS下编译安装Python2.7.6(转)
  15. Linux上vim编辑器缩进的设置(方便如书写python代码)
  16. mysql配置文件 /etc/my.cnf 详细解释
  17. [c/c++]指针(2)
  18. JS AngualrJs 指令
  19. shell入门基础&amp;常见命令及用法
  20. 20. js继承的6种方式

热门文章

  1. Collect devices information
  2. tp5 日志管理
  3. maven &quot;mvn不是内部或外部命令,也不是可运行的程序或批处理文件&quot;
  4. Linux服务器定时健康检查,发生故障自动微信告警
  5. cf1076E Vasya and a Tree (线段树)
  6. LOJ#6280. 数列分块入门 4
  7. JDK8中的并行流
  8. hdu 2149 (巴什博奕)
  9. configure: error: no acceptable C compiler found in $PATH 问题解决
  10. java ArrayList去重