hystrix封装依赖调用架构如下所示:
流程图:
四种调用方式,前两种只适用于HystrixCommand,不适用于HystrixObservableCommand
-
execute()— blocks, then returns the single response received from the dependency (or throws an exception in case of an error) -
queue()— returns aFuturewith which you can obtain the single response from the dependency -
observe()— subscribes to theObservablethat represents the response(s) from the dependency and returns anObservablethat replicates that sourceObservable -
toObservable()— returns anObservablethat, when you subscribe to it, will execute the Hystrix command and emit its responses
K value = command.execute();
Future<K> fValue = command.queue();
Observable<K> ohValue = command.observe(); //hot observable
Observable<K> ocValue = command.toObservable(); //cold observable
没有办法强制使超时的线程停止执行,hystrix可以抛出一个InterruptException异常,如果这个包装类InterruptException异常。
对于线程中断,Hystrix不能保证中断实际发生。像在JVM上运行的所有其他代码一样,您只能抛出一个InterruptedException,您不能强制包装的代码来捕获它。