官术网_书友最值得收藏!

Reactive Core and Streams

Java 8 introduced Reactive Core, which implements the Reactive programming model and is built on top of the Reactive Streams specification, a standard for building Reactive applications. As the lambda syntax gives more flexibility to go for the event-driven approach Java 8 provides the best way to support Reactive. Also, Java's lambda syntax gives us the ability to create and spawn up small and independent asynchronous tasks. One of the main goals of Reactive Streams is to address the problem of back pressure. We will talk more about back pressure in a later section of this chapter.

The main difference between Java 8 Streams and Reactive Streams is that Reactive is a push model, whereas Java 8 Streams focuses on pulling. In Reactive Streams, based on consumer needs and numbers, all events will be pushed to consumers.

Reactive programming model support is Spring 5's best feature since the last release. Also, with the support of the Akka and Play framework, Java 8 provides a better platform for Reactive applications.

Reactor is built on top of the Reactive Streams specification. Reactive Streams is a bundle of four Java interfaces:

  • Publisher
  • Subscriber
  • Subscription
  • Processor

Publisher will publish a stream of data items to the subscribers that registered with the Publisher. Using an executor, the Publisher publishes the items to the Subscriber. Also, Publisher makes sure that the Subscriber method invocations for each subscription are strictly ordered.

Subscriber consumes items only when requested. You can cancel the receiving process any time by using Subscription.

Subscription behaves as a message mediator between the Publisher and the Subscriber.

Processor represents a processing stage, which can include both Subscriber and a Publisher. Processor can initiate back pressure and cancel the subscription, as well.


Reactive Streams is a specification for asynchronous stream processing, which means all events can be produced and consumed asynchronously.
主站蜘蛛池模板: 邹城市| 宁波市| 富阳市| 达尔| 灵武市| 日喀则市| 崇信县| 临颍县| 新和县| 商水县| 赤水市| 夏津县| 永胜县| 武汉市| 习水县| 峨边| 宜兴市| 宜州市| 康马县| 东明县| 昆明市| 美姑县| 双峰县| 西乌珠穆沁旗| 炉霍县| 通州市| 崇阳县| 确山县| 庄浪县| 尼玛县| 宁陕县| 屏南县| 罗山县| 吉林省| 甘谷县| 遵义市| 松阳县| 平原县| 克拉玛依市| 右玉县| 鹤峰县|