大佬教程收集整理的这篇文章主要介绍了Spring Boot Hystrix - 在调用rest模板之前会为异常调用回退方法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚在研究断路器模式,并在 baeldung 的网站上看到了一篇很棒的文章。是关于 Spring Cloud hyStrix 用于实现这种设计模式。
它说下面的代码(没有我在 getGreeTing 方法中添加的失败部分)将执行回退方法,如果在 restTemplate 调用期间发生断路器条件。
但是如果我在 rest 模板调用之前添加了一段代码,它会抛出一个异常(除以零的部分),它还会执行回退方法(这里是 defaultGreeTing 方法)吗?
@service
public class GreeTingservice {
@HyStrixCommand(fallBACkMethod = "defaultGreeTing")
public String getGreeTing(String userName) {
// failing code before rest template -> I would not IDeally put any other code than the network call here but still,sometimes it might be there.
int x = 0,y = 3;
int z = y / x;
return new RestTemplate()
.getForObject("http://localhost:9090/greeTing/{usernamE}",String.class,userName);
}
private String defaultGreeTing(String userName) {
return "Hello User! what's up?";
}
}
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Spring Boot Hystrix - 在调用rest模板之前会为异常调用回退方法全部内容,希望文章能够帮你解决Spring Boot Hystrix - 在调用rest模板之前会为异常调用回退方法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。