使用@HystrixCommand注解
如果我们使用的是@HystrixCommand注解,那么可以在注解中直接指定超时时间,如下:
@HystrixCommand(fallbackMethod="fallback",
commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000" )
}
)
Hystrix配置整体的超时时间
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=1000
配置单个超时时间
hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMilliseconds=1000
其中HystrixCommandKey为@HystrixCommand 进行配置
example
@HystrixCommand(groupKey = "StoreSubmission", commandKey = "StoreSubmission", threadPoolKey = "StoreSubmission")
public String storeSubmission(ReturnType returnType, InputStream is, String id) {
}
@HystrixCommand需要引入依赖
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
<version>${hystrix-version}</version>
</dependency>
在fegin中配置超时时间
在fegin中无法使用@HystrixCommand来单独进行配置
hystrix.command.MyService#getLastTimeData(Map).execution.isolation.thread.timeoutInMilliseconds
本文介绍了如何在Java应用中使用@HystrixCommand注解来设定方法的超时时间,以及如何在全局和单个命令级别配置Hystrix超时。通过设置execution.isolation.thread.timeoutInMilliseconds属性,可以防止服务雪崩。同时,文章提及在Feign客户端中配置超时的方法。并提供了相关的Maven依赖。
8万+

被折叠的 条评论
为什么被折叠?



