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

Reactor types

Project Reactor is built with two core types based on the number of elements they process. They are considered as main building blocks to create a Reactive System using Reactor. They are Flux and Mono. They both implement the Publisher<T> interface and conform to Reactive Streams specification, and  are furnished with reactive-pull and back-pressure facility. They also have several other useful methods. Let's explore the details as follows: 

  • Flux: It can be considered the equivalent of RxJava's Observable and can emit zero or more items, ending successfully or with an error signal. In short, it represents asynchronous event streams having zero or more elements. 
  • Mono: It can emit, at most, one element at a time. It is equivalent of the Single and Maybe Observable type from the RxJava side. A Mono type can be used for one-to-one request-response model implementation; for example, a task wish to send a completion signal can use a Mono type reactor.

The clear difference between the number of elements a reactor type can handle provides useful semantics and makes it an easy decision to choose which reactor type. If the model is sort of fire and forget then choose the Mono type. If execution is dealing with multiple data items or elements in the stream, then the Flux type is more appropriate.

Additionally, various operators play a vital role in deciding the type of reactor. For example, calling asingle() method on a Flux<T> type will return Mono<T>, while concatenating multiple entities of type Mono<T> together with concatWith() will result in the Flux<T> type. The reactor type can influence which operators we can use with it. For example, some operators are applicable to either one of  Flux or Mono while others can be used for both of them. 

主站蜘蛛池模板: 精河县| 高安市| 仪征市| 额敏县| 邮箱| 托克逊县| 盐边县| 莲花县| 黎平县| 辽中县| 乌苏市| 九寨沟县| 江口县| 桦川县| 新竹县| 思南县| 东丰县| 永城市| 凤城市| 翁源县| 易门县| 新和县| 原阳县| 商城县| 灵璧县| 河北省| 成安县| 泊头市| 抚远县| 巍山| 伊金霍洛旗| 万荣县| 平罗县| 铜山县| 固原市| 全南县| 顺昌县| 湘阴县| 顺平县| 防城港市| 长垣县|