咱們先聊下什么是Reactive,官網給的定義如下:
Reactive systems have certain characteristics that make them ideal for low-latency, high-throughput workloads. Project Reactor and the Spring portfolio work together to enable developers to build enterprise-grade reactive systems that are responsive, resilient, elastic, and message-driven.
反應式系統具有某些特性,使其成為低延遲、高吞吐量工作負載的理想選擇。 Project Reactor 和 Spring 產品組合協同工作,使開發人員能夠構建具有響應性、彈性、彈性和消息驅動的企業級反應式系統。
What is reactive processing?
響應式處理是一種范例,它使開發人員能夠構建可以處理背壓(流控制)的非阻塞、異步應用程序。
Why use reactive processing?
Reactive systems better utilize modern processors. Also, the inclusion of back-pressure in reactive programming ensures better resilience between decoupled components.
反應式系統更好地利用現代處理器。 此外,在反應式編程中包含背壓可確保解耦組件之間具有更好的彈性。
什么是響應式編程(Reactive Programming)?
維基百科上的定義是:reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change
響應式編程(reactive programming)是一種基于數據流(data stream)和變化傳遞(propagation of change)的聲明式(declarative)的編程范式
? ? ? ?聲明式(declarative):?Lambda 表達式
Lambda表達式創建線程的時候,并不關心接口名,方法名,參數名。只關注他的參數類型,參數個數,返回值。
jdk:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 表格中的一元接口表示只有一個入參,二元接口表示有兩個入參
? ? ? ? ? 數據流:Stream:
Reactive Streams 接口:
Publisher:負責發布類型為T的元素,并為訂閱者提供連接到它的訂閱方法
Subscriber:連接Publisher,通過onSubscribe接收確認,然后通過onNext接收數據,通過onError和onComplete回調和返回其他信號
Subscription:代表發布者和訂閱者之間的鏈接,允許通過請求對發布者進行背壓,或者取消終止鏈接
Processor:在單個接口中結合了Publisher和Subscriber的功能