AdSense

網頁

2020/3/3

什麼是Reactive Streams(響應式流)?

節錄Reactive Streams官方頁面第一段說明:

Reactive Streams is an initiative to provide a standard for asynchronous stream processing with non-blocking back pressure. This encompasses efforts aimed at runtime environments (JVM and JavaScript) as well as network protocols.

也就是說,Reactive Streams是一個非阻塞(non-blocking)回壓(back pressure)的非同步流處理(asynchronous stream)的標準倡議。

換句話說,Reactive Streams提供操作「非阻塞回壓的非同步串流處理」所需的介面,方法及協議的API規格

Reactive Streams定義了以下四個API元件:

  1. Publisher 發布者:發布資料流。
  2. Subscriber 訂閱者:訂閱發布者。
  3. Subscription 訂閱:訂閱者對發布者的訂閱。
  4. Processor 處理器:身兼發布者及訂閱者,處理資料。

Reactive Streams的角色就像是JPA,JDBC等API,皆僅定義操作所需的標準介面及方法,而使用時需要實作才能運行。例如JPA的實作有Hibernate或EclipseLink;而Reactive Streams在Java的實作則有RxJava 2.xReactor等。

那Reactive Streams和Reactive Programming(響應式程式設計)的關係是什麼呢?

Reactive Programming是一種程式典範(paradigm),就如同Object-Oriented Programming(物件導向程式設計)也是一種程式典範,Reactive Streams則是Reactive Programming的API規格。


參考:

沒有留言:

AdSense