Is really necessary to use Hystrix with reactive s

2020-06-28 05:41发布

问题:

I'm working in a project in which we are moving some of ours microservices from Spring-MVC to Spring-Webflux to test the reactive paradigm. Looking for some help in the github repository of hystrix we've noted that the project have no commits since a year ago, and it's based in RxJava, so there are some incompatibilities with project-reactor.

We're having some issues using Hystrix, particulary that the annotations from "Javanica" doesn't work and our developers need to use HystrixCommands from Spring-Cloud instead. And the fact that Hystrix, obviously, creates his own pool of threads aside from the ones of reactor.

Reached this point my question is not how to use Hystrix with Spring Boot 2.0 but if it's a must to wrap all the external calls from our microservices in an HystrixCommand or if simply using the Reactor methods (timeout, onError, retry, etc.) we can avoid this wrapping.

回答1:

You could replace many of hystrix features with built-in Reactor methods (timeout, retry, limitRate, onError...).

For circuit breaker you could use Resilience4j. It is easy to embed it into existent Reactor code

Mono<MyClass> myMono = ...;
CircuitBreaker circuitBreaker = ...;
myMono.transform(CircuitBreakerOperator.of(circuitBreaker)).subscribe(...)