6.Hystrix-超时设置
2024-09-12 10:02:04
由于客户端请求服务端方法时,服务端方法响应超过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>
最新文章
- jdk8飞行记录器配置
- Windows 之 删除文件出现“该项目不在请确认该项目的位置”
- 设置transparent是否多此一举
- YCbCr
- Delphi 记事本 TMemo(5篇)
- 11g的alert日志路径
- poj1163The Triangle(简单DP)
- 第四章——SQLServer2008-2012资源及性能监控(1)
- linux centos7 安装redis
- websocket(三) 进阶!netty框架实现websocket达到高并发
- 从初识Maven到使用Maven进行依赖管理和项目构建
- Object.defineProperty实现数据绑定
- 解决mongodb的安装mongod命令不是内部或外部命令
- 2、CentOS下编译安装Python2.7.6(转)
- Linux上vim编辑器缩进的设置(方便如书写python代码)
- mysql配置文件 /etc/my.cnf 详细解释
- [c/c++]指针(2)
- JS AngualrJs 指令
- shell入门基础&;常见命令及用法
- 20. js继承的6种方式
热门文章
- Collect devices information
- tp5 日志管理
- maven ";mvn不是内部或外部命令,也不是可运行的程序或批处理文件";
- Linux服务器定时健康检查,发生故障自动微信告警
- cf1076E Vasya and a Tree (线段树)
- LOJ#6280. 数列分块入门 4
- JDK8中的并行流
- hdu 2149 (巴什博奕)
- configure: error: no acceptable C compiler found in $PATH 问题解决
- java ArrayList去重