Reactive Streams

397 阅读7分钟

Reactive Streams

//反应式流 Reactive Streams is an initiative to provide a standard for asynchronous stream processing with non-blocking back pressure. This encompasses efforts aimed at runtime environments (JVM and JavaScript) as well as network protocols. 反应式流提倡提供一个没有阻塞背压的异步流处理。这包括针对运行时环境(JVM and JavaScript)和网络协议的工作。 efforts:努力,(为达到某一目的)有组织的活动,一系列的活动

JDK9 java.util.concurrent.Flow

The interfaces available in JDK9’s[java.util.concurrent.Flow](%3Ca href="docs.oracle.com/javase/9/do…"%3Ehttps://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html%3C/a%3E), are 1:1 semantically equivalent to their respective Reactive Streams counterparts. This means that there will be a migratory period, while libraries move to adopt the new types in the JDK, however this period is expected to be short - due to the full semantic equivalence of the libraries, as well as the Reactive Streams <-> Flow adapter library as well as a TCK compatible directly with the JDK Flow types. java9的 java.util.concurrent.Flow可用的接口在语义上等效与他们各自的reactive Streams 对应物。这意味将有一个迁徙期,当库转变为采用JDK中的新类型。然而这个周期以及很短,由于语义完全与库对等, 以及Reactive Streamer<-> 流适配器以及直接与JDK flow类型兼容的TCK

TCK:技术兼容性套件 counterparts:对应物,相关者,副本 flow:流,流量 adapter:适配器 Readthis if you are interested in learning more about Reactive Streams for the JVM. 阅读他如果你有兴趣学习更多与JVM相关的Reactive Streamer。

The Problem

问题 Handling streams of data—especially “live” data whose volume is not predetermined—requires special care in an asynchronous system. The most prominent issue is that resource consumption needs to be controlled such that a fast data source does not overwhelm the stream destination. Asynchrony is needed in order to enable the parallel use of computing resources, on collaborating network hosts or multiple CPU cores within a single machine. The main goal of Reactive Streams is to govern the exchange of stream data across an asynchronous boundary—think passing elements on to another thread or thread-pool—while ensuring that the receiving side is not forced to buffer arbitrary amounts of data. In other words, back pressure is an integral part of this model in order to allow the queues which mediate between threads to be bounded. The benefits of asynchronous processing would be negated if the communication of back pressure were synchronous (see also the Reactive Manifesto), therefore care has to be taken to mandate fully non-blocking and asynchronous behavior of all aspects of a Reactive Streams implementation. 处理数据流,特别是大小不确定的“实时”数据,需要在异步系统中特别小心。最突出的问题是需要控制资源消耗,以便一个快速的数据源不会压倒目标流。需要异步才能在单个计算机上的协作网络主机,或多种cpu核心并行的使用计算机资源。 反应流的主要目标是管理穿过异步边界的流数据交换。---思考将元素传递在一个线程或一个线程池---当确保收到的一边不会强制缓冲任意数量的数据。换句话说,背压是这种模型的一个完整部分,为了允许在线程之间的队列是有界的。异步处理的好处将被否定,如果背压的通信是同步的()。因此必须注意强制要求反应式流实现所有方面完全不堵塞的和异步行为。 force:v. 暴力的 arbitrary: adj. 任意的;武断的,霸道的 requires: v. 需要 issue: n.问题 prominent: adj. 显著的,突出的 consumption:消耗,消费,肺痨 overwhelm:压倒 collaborating: adj. 协作的 collaborate:vi. 合作,通敌 collaboration:n. 合作通敌

It is the intention of this specification to allow the creation of many conforming implementations, which by virtue of abiding by the rules will be able to interoperate smoothly, preserving the aforementioned benefits and characteristics across the whole processing graph of a stream application.

本说明书旨在允许创建许多符合要求的实现,这些实现通过遵守规则能够顺利的互操作。 并在整个流应用的处理图中保留前述的好处和特点 intention:intened 意图,旨在 specification:规范,说明 conforming:符合 implementations:实现 interoperate:互操作 smoothly:顺利,顺手,自如,顺当 by virtue of abiding by the rules:遵守规则

Scope

范围 The scope of Reactive Streams is to find a minimal set of interfaces, methods and protocols that will describe the necessary operations and entities to achieve the goal—asynchronous streams of data with non-blocking back pressure. 反应式流的范围是找到一系列最小的接口,方法和协议可以描述必要的操作和实体去实现这个目标:不阻塞背压的数据异步流。 End-user DSLs or protocol binding APIs have purposefully been left out of the scope to encourage and enable different implementations that potentially use different programming languages to stay as true as possible to the idioms of their platform. 有目的的将最终使用DSLs或者必须遵守的API协议的被排除在范围之外。去鼓励和启用能使潜在的不同的编程语言的不同实现,如此可能保留这个平台的惯用语

We anticipate that acceptance of this Reactive Streams specification and experience with its implementations will together lead to wide integration, for example including Java platform support in future JDK releases or network protocol support in future web browsers. 我们预想,接受这个反应流的规范和实现经验将共同导致更多的融合。例如包括在以后jdk版本java平台支持或者在以后web浏览器网络协议支持。 anticipate:预计

Working Groups

工作组

Basic Semantics

基本语义 The basic semantics define how the transmission of stream elements is regulated through back-pressure. How elements are transmitted, their representation during transfer, or how back-pressure is signaled is not part of this specification. 基本语义规定流元素的传输是怎样通过背压调整。元素是怎样传输的。传输时 的表示或如何发出背压信号,不在这一部分详述。

JVM Interfaces (Completed)

This working group applies the basic semantics to a set of programming interfaces whose main purpose is to allow the interoperation of different conforming implementations and language bindings for passing streams between objects and threads within the JVM, using the shared memory heap. As of August 23rd, 2019 we have released version 1.0.3 of Reactive Streams for the JVM, including Java API, a textual Specification, a TCK and implementation examples.

这个工作组将基础语义应用到一系列的编程接口。他们的主要目的是允许使用共享记忆堆在JVM中的对象与线程之间传递流。从而实现不同的符合要求的实现和语言绑定可以互操作。在2019年8月23日,我们反应流for jvm 的1.0.3版本,包括java api,文字详述,a TCK和实现范例。

New in 1.0.3 is that the JDK9 [adapter library] is included in the main jar.Corresponding code artifacts are available on Maven Central:

1.0.3的新功能是主jar中含有包含JDK9(适配器库) Maven Central提供相应的代码工件

  1. `
  2. org.reactivestreams
  3. reactive-streams
  4. 1.0.3
  5. org.reactivestreams
  6. reactive-streams-tck
  7. 1.0.3
  8. org.reactivestreams
  9. reactive-streams-tck-flow
  10. 1.0.3
  11. org.reactivestreams
  12. reactive-streams-examples
  13. 1.0.3
  14. `

The source code for these is available on github. Please use github issues for providing feedback. 这些源码在GitHub上都可以找到,请使用GitHub issue 提供反馈。 All artifacts and specifications are released under Creative Commons Zero into the Public Domain. 所有的组件和说明通过知识共享零下发布到公共领域。 realease into发布到 Read more about Reactive Streams 1.0.3 for the JVM here.

A Note for Implementors

实施者须知 To get started implementing the final specification, it is recommended to start by reading the README and the Java API documentation, then taking a look at the Specification then taking a look at the TCK and the example implementations. If you have an issue with any of the above, please take a look at closed issues and then open a new issue if it has not already been answered. 为了实施最后的规范,建议先阅读README和JAVA API文档,然后再看一下规范再看一下TCK和实施范例。如果对以上有任何问题,请看一下已解决的问题,如果尚未解决,请打开一个新的问题。 This work was performed in the reactive-streams-jvm repository.

JavaScript Interfaces

JavaScript 界面 This working group defines a minimal set of object properties for observing a stream of elements within a JavaScript runtime environment. The goal is to provide a testable specification that allows different implementations to interoperate within that same runtime environment. This work is performed in the reactive-streams-js repository.

Network Protocols

This working group defines network protocols for passing reactive streams over various transport media that involve serialization and deserialization of the data elements. Examples of such transports are TCP, UDP, HTTP and WebSockets .This work is performed in the reactive-streams-io repository.