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

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.
主站蜘蛛池模板: 汝阳县| 凤台县| 谷城县| 乌兰察布市| 泾川县| 会泽县| 嘉祥县| 房产| 藁城市| 嘉义市| 乡城县| 龙泉市| 平昌县| 木兰县| 兴义市| 绍兴县| 武夷山市| 保亭| 芒康县| 郎溪县| 洪泽县| 长丰县| 信宜市| 平利县| 孙吴县| 桐乡市| 文登市| 新安县| 上饶市| 永宁县| 阿瓦提县| 洛宁县| 乌兰察布市| 达拉特旗| 昆山市| 巴彦县| 轮台县| 鲁甸县| 平阳县| 兰坪| 合江县|