- Spring 5.0 Projects
- Nilang Patel
- 313字
- 2021-07-02 12:35:06
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.
- 物聯(lián)網(wǎng)短距離無線通信技術(shù)應(yīng)用與開發(fā)
- 物聯(lián)網(wǎng)智慧安監(jiān)技術(shù)
- 網(wǎng)絡(luò)創(chuàng)新指數(shù)研究
- Getting Started with WebRTC
- 5G技術(shù)與標(biāo)準(zhǔn)
- 網(wǎng)絡(luò)設(shè)計(jì)與應(yīng)用(第2版)
- 局域網(wǎng)組成實(shí)踐
- Hands-On Bitcoin Programming with Python
- 圖神經(jīng)網(wǎng)絡(luò)前沿
- 物聯(lián)網(wǎng)與智慧農(nóng)業(yè)
- 區(qū)塊鏈社區(qū)運(yùn)營手冊
- 算力網(wǎng)絡(luò):云網(wǎng)融合2.0時(shí)代的網(wǎng)絡(luò)架構(gòu)與關(guān)鍵技術(shù)
- 無線傳感器網(wǎng)絡(luò)定位方法及應(yīng)用
- 路由與交換技術(shù)
- Hands-On Microservices:Monitoring and Testing