Difference between HystrixCommand and HystrixObservableCommand

I am trying to understand the difference between HystrixCommand and HystrixObservableCommand. The reason I got confused is the HysterixCommand method, also having the observ () or toObservable () method, which emits hot and cold observables respectively. So what was the need to create a HystrixObservableCommand. If I work completely on non-blocking calls, which should I use? why?

+6
source share
2 answers

From Javadocs:

Hystrixcommand

This command is essentially a blocking command, but provides an observable facade if used with the observation function ()

HystrixObservableCommand

This command should be used for a purely non-blocking call pattern. The caller of this command will be subscribed to the Observable returned by the run () method.

The difference is that the HystrixCommand supports the blocking paradigm by default, but also provides non-blocking behavior through Observables through the faรงade, while the HystrixObservableCommand is implemented specifically for a non-blocking installation. I'm not quite sure why it split into two implementations, but I would suggest that the reason is that initially HystrixCommand did not support non-blocking. This was added about a year or so after the initial implementation . Maybe it was just cleaner to write a purely non-blocking class.

If you only work with non-blocking calls, most likely you should use the HystrixObservableCommand. Ben Christensen, one of the developers of Hystrix, perfectly sums up this post:

However, if you block call blocking, you should just stick with the use of HystrixCommand, as the one built for it by default starts everything in a separate thread. Using HystrixCommand.observe () will give you the simultaneous, asynchronous that you are looking for.

HystrixObservableCommand is designed to bypass asynchronous, non-blocking Observables that do not need additional threads.

+10
source

In addition to Nick Defazio's answer, an implementation of the HystrixObservableCommand wrap Observables that can emit multiple elements, while the HystrixCommand will never emit more than one element, even if you call observe() or .toObservable() , which are only wrapping a single value, reconfigured by the run() method.

+4
source

All Articles