spring cloud hystrix 超时时间使用方式详解
我们在使用后台微服务的时候,各个服务之前会有很多请求和交叉业务。这里会引起雪崩、超时等异常处理。SpringCloudHystrix服务降级、容错机治理使hystrix有很好的支持,引入后实现断路器功能。
1:pom 引入jar包
org.springframework.cloud spring-cloud-starter-netflix-hystrix
2:添加注解
Application中增加@EnableCircuitBreaker开启hystrix功能
3:配置文件配置
注意:feign中的hystrix的enabled属性要设置true
hystrix: command: transferApprove:#这里是要设置超时时间的方法,如新增其他方法需要增加此节点信息。 execution: isolation: thread: timeoutInMilliseconds:6000#默认连接超时时间是1秒
4:增加代码
代码注意fastOrBatchFallback的出参和入参要和设置了@HystrixCommand注解方法一致,否则会抛出异常。
@Override @HystrixCommand(fallbackMethod="fastOrBatchFallback") publicResultModeltransferApprove(TransferApproveDtodto){ log.info("调动流程审批:{}",dto); if(StringUtils.isEmpty(dto.getOperatorId()) ||StringUtils.isEmpty(dto.getFlowNos()) ||StringUtils.isEmpty(dto.getOperatorId())){ returnResultModel.fail(-1,"参数异常"); } } publicResultModelfastOrBatchFallback(TransferApproveDtotransferApproveDto){ log.info("请求ps服务超时,请稍后再试.入参:{}",GsonUtils.toJsonString(transferApproveDto)); returnResultModel.fail("请求服务超时,请稍后再试","ps服务超时,请稍后再试"); }
5:待解决和研究问题?
hystrix执行了Fallback之后是否继续走其他逻辑,目前可知的是继续走其他逻辑,如果让它不触发后序的逻辑怎么配置?
这里先打一个问号,欢迎大家一起讨论和解决。
到此这篇关于springcloudhystrix超时时间使用方式的文章就介绍到这了,更多相关springcloud超时时间内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。