问题描述
该项目使用SpringBoot(2.3.4)
和SpringCloud(Hoxton.SR8)
。
共有三类:BillController,BillService(接口)和BillServiceImpl(实现BillService),BillController调用在BillService中声明的函数getBillList
。
在BillServiceImpl中,有两种方法,一种是getBillList
,另一种是simulateUnstableService
,getBillList
调用simulateUnstableService
,而在simulateUnstableService
中只是很长一段时间睡眠(2000年)。
奇怪的是,如果我用getBillList
对HystrixCommand
进行注释,那么它可以按我期望的那样工作。但是,如果我移动HystrixCommand
来对simulateUnstableService
进行注释,则不会中断,这意味着超时不会触发Circuit Breaker
。
@Service
public class BillServiceImpl implements BillService {
@Override
// have effact
@HystrixCommand(
commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
}
)
public List<Bill> getBillList(long userId) {
return simulateUnstableService(userId);
}
// no effact
// @HystrixCommand(
// commandProperties = {
// @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
// }
// )
public List<Bill> simulateUnstableService(long userId) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return new ArrayList<>();
}
}
还有更多,如果我只是将simulateUnstableService
方法的内容复制到getBillList
,并用HystrixCommand注释getBillList,则断路器也可以工作。
为什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)