Java 响应式框架的比较

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33671578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 21:58:07  来源:igfitidea点击:

Comparison of Java reactive frameworks

javaakkareactive-programmingrx-javaproject-reactor

提问by Florian Beaufumé

I see many frameworks/libraries that claim that they can help build reactive applications in Java, such as: Akka, Vert.x, RxJava, Reactor, QBit, etc.

我看到很多框架/库声称它们可以帮助用 Java 构建响应式应用程序,例如:Akka、Vert.x、RxJava、Reactor、QBit 等。

They seem to have different approaches, features, pros, cons, etc. I could not find detailled comparisons. There is documentation about each of these framerwork, but it is not enough for me to understand the differences.

它们似乎有不同的方法、功能、优点、缺点等。我找不到详细的比较。有关于这些框架中的每一个的文档,但对我来说理解这些差异还不够。

What are the differences between the major Java reactive frameworks?

主要的 Java 响应式框架之间有什么区别?

And what are the application requirements that can drive the choice of a Java reactive framework?

哪些应用程序要求可以推动选择 Java 响应式框架?

Thank you for your time.

感谢您的时间。

回答by akarnokd

I'm working on RxJava and I did some evaluationson Akka-Streams and Reactor recently.

我正在研究 RxJava,最近我对 Akka-Streams 和 Reactor做了一些评估

As far as I can tell with all the libraries, they converge to a single concept called Reactive-Streamsso you can go back and forth between the implementations.

据我所知,所有的库都集中在一个叫做Reactive-Streams 的概念上,这样你就可以在实现之间来回切换。

I believe RxJavais the most generic of all, has zero dependencies on other libraries and is not opinionated about concurrency. It is very popular on Android mainly due to support by other libraries/frameworks such as Retrofit. The 1.x branch doesn't implement Reactive-Streams but has wrappers for it whereas 2.x is natively Reactive-Streams compliant (currently available in preview). Many popular JVM-based programming languages have adaptors for it (Scala, Kotlin, Clojure, etc).

我相信RxJava是最通用的,对其他库的依赖为零,并且对并发性没有偏见。它在 Android 上非常流行,主要是由于其他库/框架(例如 Retrofit)的支持。1.x 分支没有实现 Reactive-Streams,但有包装器,而 2.x 是原生的 Reactive-Streams 兼容(目前在预览版中可用)。许多流行的基于 JVM 的编程语言都有它的适配器(Scala、Kotlin、Clojure 等)。

Reactoris Reactive-Streams compliant as it is more recent library. They have dependencies/support for a lot of other libraries. They chose a different set of tradeoffs when it comes to concurrency and queueing in the streams (i.e., LMAX Disruptor-style). There were a few back and forth between it and RxJava regarding operators and we've started talking about having a shared pool of operators.

Reactor是 Reactive-Streams 兼容的,因为它是更新的库。它们对许多其他库具有依赖性/支持。当涉及到流中的并发性和队列时,他们选择了一组不同的权衡(即 LMAX Disruptor 风格)。在它和 RxJava 之间有一些关于操作符的来回讨论,我们已经开始讨论拥有一个共享的操作符池。

Akkais highly dominated by Scala-like concepts; I had a small trouble getting it to work. The team behind it were involved in developing the Reactive-Streams specification and there is an Akka-Streams library that is advertised to support Reactive-Streams, however, accessing it is cumbersome because its fluent API is heavily intertwined with the Akka actor model.

Akka被类 Scala 的概念高度支配;我在让它工作时遇到了一个小麻烦。它背后的团队参与了 Reactive-Streams 规范的开发,并且有一个 Akka-Streams 库被宣传为支持 Reactive-Streams,但是,访问它很麻烦,因为其流畅的 API 与 Akka actor 模型密切相关。

If you are on the server/desktop/Android side, RxJava is generally a good choice (and I believe is documented better than the others) and is aimed at high-throughput asynchronous operations. If you are more on the latency side, Reactor might be a better choice. I don't know much about the usages of Akka-Streams but I saw one benchmark a year ago where a web-server built around Akka outperformed Tomcat and Netty+RxJava.

如果您在服务器/桌面/Android 端,RxJava 通常是一个不错的选择(我相信文档比其他的更好)并且针对高吞吐量异步操作。如果您更关注延迟,Reactor 可能是更好的选择。我不太了解 Akka-Streams 的用法,但我在一年前看到一个基准测试,其中围绕 Akka 构建的 Web 服务器的性能优于 Tomcat 和 Netty+RxJava。