Hystrix Run Templates

I am trying to wrap my head around Hystrix and after reading their documents there is still a question about its usage patterns.

First, I don’t understand how to use the Asynchronous script compared to their Reactive execution. The only difference I see is that asynchronous execution is not always blocked, while Reactive may or may not be blocked. Therefore, I assume that my real question is:

  • What is the difference between synchronous and blocking reactive execution ?; and
  • What is the difference between asynchronous and non-blocking reactive execution?
+8
java asynchronous fault-tolerance reactive-programming hystrix
source share
1 answer

Suppose you wrapped two calls to service A and B as a HystrixCommand . You now have three options:

use .execute() : pure synchronous call. You call the method and continue your program as soon as the result is received. The total execution time of a program is the sum of both calls. The main stream of your program is very linear.

use .queue() : get Future immediately for both commands. Both service calls are made in parallel. Then use .get() to get the results. These calls are blocked until a result is found. Your total lead time is faster than before: your lead time will be the duration of the longest service call. Use this when you want to combine the results of two services. The main thread of your program is still linear, although both calls are made in parallel.

use .subscribe() : immediately get Observable for both commands. Both service calls are made in parallel. Then use .subscribe() to register a callback for the action on the result after it is available. This is very useful if you do not want to combine the results and want to independently respond to the results of service A and B after their arrival. The main thread of your program is not linear, but reactive: the program flow will continue inside the callback for each command.

Hope this helps.

+20
source share

All Articles