问题描述
我正在一个项目中,我们正在将一些微服务从Spring-MVC迁移到Spring-Webflux,以测试反应性范例.在hystrix的github存储库中寻求帮助时,我们注意到该项目自一年前以来就没有提交,它基于RxJava,因此与project-reactor存在一些不兼容性.
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.
我们在使用Hystrix时遇到了一些问题,特别是来自"Javanica"的注释不起作用,并且我们的开发人员需要使用Spring-Cloud中的HystrixCommands.而且,Hystrix显然会在反应堆之外创建自己的线程池.
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.
到达这一点,我的问题不是如何在Spring Boot 2.0中使用Hystrix,而是是否必须将来自微服务的所有外部调用包装在HystrixCommand中,或者是否仅使用Reactor方法(超时,onError,重试等). .)我们可以避免这种包裹.
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.
推荐答案
您可以用内置的Reactor方法(超时,重试,limitRate,onError ...)替换许多hystrix功能.
You could replace many of hystrix features with built-in Reactor methods (timeout, retry, limitRate, onError...).
对于断路器,您可以使用 Resilience4j .很容易将其嵌入到现有的Reactor代码中
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(...)
这篇关于将Hystrix与反应式Spring Boot 2应用程序结合使用真的必要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!