比方说,我具有启用Hystrix断路器和回退的以下代码:
@Component
public class MyServiceProxy {
@HystrixCommand(fallbackMethod = "syncFallback")
public Future <MyClass> asyncCall() {
return new AsyncResult <MyClass> () {
@Override
public MyClass invoke() {
return new MyClass();
}
};
}
private MyClass syncFallback() {
return new MyClass();
}
}
服务类是这样的:
@Service
public class UseMyService {
@Inject
public MyServiceProxy myServiceProxy;
public void getResults() {
/*
In the case of a fallback the fallback method will
return a non future result and how does this piece of code not fail ?
I expected the below call to fail when fallback method is called.
*/
Future <MyClass> myClassFutureResponse = myServiceProxy.asyncCall();
try {
MyClass actualResponse = myClassFutureResponse.get();
} catch (Exception e) {
}
}
}
这是我的问题:
据我所知,调用方法将预期异步结果(未来),但回退将返回未来的响应,并且不应允许调用get,并且代码应引发异常,但显然不会发生,并且可以正常工作符合预期(不进行任何强制转换)。
任何帮助我理解这一概念的细节/见解都将是很棒的!