-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hystrix 1.4 API Design Review #321
Comments
Note that the reason for |
Here is async command usage: public class ExampleAsyncCommand extends HystrixAsyncCommand<String> {
protected ExampleAsyncCommand() {
super(HystrixCommandGroupKey.Factory.asKey("ExampleAsync"));
}
@Override
protected HystrixFuture<String> run() {
Promise<String> p = Promise.create();
new Thread(new Runnable() {
@Override
public void run() {
p.onSuccess("hello");
}
}).start();
return p.createFuture();
}
@Override
protected HystrixFuture<String> getFallback() {
Promise<String> p = Promise.create();
p.onSuccess("hello fallback");
return p.createFuture();
}
} |
Here is observable command usage: public class ExampleObservableCommand extends HystrixObservableCommand<String> {
ExampleObservableCommand() {
super(HystrixCommandGroupKey.Factory.asKey("ExampleObservable"));
}
@Override
protected Observable<String> construct() {
return Observable.just("hello", "world").subscribeOn(Schedulers.io());
}
@Override
protected Observable<String> onFailureResumeWithFallback() {
return Observable.just("hello fallback");
}
} |
Any reason HystrixObservable doesn't include toObservable(Scheduler)? The copied javadocs reference using HystrixCommand.toObservable(Scheduler). |
And should there be an interface that implements both HystrixExecutable and HystrixObservable, so that implementations that provide both options (eg HystrixCommand) can be passed around more easily? |
This method has been removed and was only ever intended as an implementation detail anyways.
What do you suggest calling it? |
Hmm, I thought I had a use for it, but I'm possibly misunderstanding something. I'll post to the group with my use case for comment
HystrixRunnable? HystrixInvokable, and rename the marker interface to something else (HystrixCallable?) |
@bbaetz You can achieve the same callback scheduling behavior by using the RxJava |
I'd like to consider renaming |
On the |
For |
There's nothing intrinsically Hystrix-y about the |
For |
I like this.
Yes. But I'm far from ready for that -> ReactiveX/RxJava#1594 Due to that not being ready I can't rely on it here. So do we move forward with this interface in Hystrix, or skip |
I'm fine with the shorter |
Oh probably. |
I'm good with that. |
While reviewing with @KoltonAndrus Also discussed |
While maturing the object model we now have |
As per discussion with @KoltonAndrus and @mattrjacobs we will remove |
The design of Hystrix 1.4 needs to evolve based on experience using the release candidates. This is the primary reason I haven't shipped a final 1.4.0 ... not having had the confidence in the APIs and reserving the right to change them. Discussions in #317, #315, #223 and internally at Netflix have shaped some changes currently committed but not yet released.
HystrixAsyncCommand
This is new. It is to provide non-blocking functionality like
HystrixObservableCommand
but only support scalar responses. This is to address the nuances of fallback and timeout behavior with streaming results (see #317 and #315) and the issue with the generics onHystrixExecutable
not working with streaming.Here are particular pieces of code worth reviewing:
run() ->
Hystrix/hystrix-core/src/main/java/com/netflix/hystrix/HystrixAsyncCommand.java
Line 261 in 62ac93f
HystrixFuture -
Hystrix/hystrix-core/src/main/java/com/netflix/hystrix/HystrixAsyncCommand.java
Line 197 in 62ac93f
Promise -
Hystrix/hystrix-core/src/main/java/com/netflix/hystrix/HystrixAsyncCommand.java
Line 232 in 62ac93f
I’m not convinced I’ve got the HystrixFuture/Promise API or names correct. Functionally it seems correct though.
HystrixObservableCommand
This is functionally the same as
HystrixObservableCommand
during all of the 1.4.0 release candidates, except it removes theexecute
andqueue
methods and doesn't implementHystrixExecutable
because of the generics issues (#315).It also renames the
run
andgetFallback
methods to be more clear:construct() -
Hystrix/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCommand.java
Line 191 in 62ac93f
onFailureResumeWithFallback() -
Hystrix/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCommand.java
Line 208 in 62ac93f
I don’t like the name of the ‘onFailureResumeWithFallback’ but getFallback() doesn’t work. constructFallback() would work, but I was trying to communicate the fact that it is “resuming” after failure.
What do you think we should do here?
Here is a unit test showing the partial success with fallback use case:
Hystrix/hystrix-core/src/test/java/com/netflix/hystrix/HystrixObservableCommandTest.java
Line 6287 in 62ac93f
Interfaces
I have had to massage the interfaces because HystrixObservableCommand can’t implement HystrixExecutable. The plugins need something that all 3 implement. They can do HystrixObservable but that seems too focused so I am using a marker interface (HystrixInvokable) despite not really liking marker interfaces.
It means the old stuff is deprecated because I can’t break the APIs. Not ideal but I think it’s working.
https://github.com/Netflix/Hystrix/blob/62ac93f94c7248c2a5bac596344bac0f332fdf7f/hystrix-core/src/main/java/com/netflix/hystrix/HystrixExecutable.java (This can’t be implemented by HystrixObservableCommand)
https://github.com/Netflix/Hystrix/blob/62ac93f94c7248c2a5bac596344bac0f332fdf7f/hystrix-core/src/main/java/com/netflix/hystrix/HystrixExecutableInfo.java
https://github.com/Netflix/Hystrix/blob/62ac93f94c7248c2a5bac596344bac0f332fdf7f/hystrix-core/src/main/java/com/netflix/hystrix/HystrixInvokable.java
https://github.com/Netflix/Hystrix/blob/62ac93f94c7248c2a5bac596344bac0f332fdf7f/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservable.java
Collapsers
https://github.com/Netflix/Hystrix/blob/62ac93f94c7248c2a5bac596344bac0f332fdf7f/hystrix-core/src/main/java/com/netflix/hystrix/HystrixObservableCollapser.java
https://github.com/Netflix/Hystrix/blob/62ac93f94c7248c2a5bac596344bac0f332fdf7f/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java
I still need to add HystrixAsyncCollapser.
Note that HystrixObservableCollapser is different than HystrixCollapser in how the functions are applied. AsyncCollapser will be similar but need to address a batch response type as a scalar value rather than a stream.
I would appreciate a review of the public APIs before locking this down and releasing 1.4.0 Final.
The text was updated successfully, but these errors were encountered: