- Spring 5.0 Projects
- Nilang Patel
- 261字
- 2021-07-02 12:35:02
Subscriber rules
Subscriber has the following interface definition:
public interface Subscriber<T> {
public void onSubscribe(Subscription s);
public void onNext(T t);
public void onError(Throwable t);
public void onComplete();
}
Rule number 2.1 says, A Subscriber must signal demand via Subscription.request(long n) to receive onNext signals. This rule is in line with Publisher rule number 1.1 in the sense that it establishes the responsibility of Subscriber to inform when and how many messages it is able and willing to receive.
Rule number 2.4 says, .onComplete() and Subscriber.onError(Throwable t) must consider the Subscription cancelled after having received the signal. Here again, the design intention at play is highlighted. The design sequence of sending ensures that the process of the message being sent from Publisher to Subscriber is completely decoupled. Therefore, Publisher is not bound by the Subscriber intent to keep listening, hence ensuring a non-blocking arrangement.
As soon as Publisher sends out a message, it has no messages to be sent with Subscriber.onComplete() and the Subscription object is no longer valid/available. This is similar to when an exception is thrown back with Subscriber.onError(Throwable t). The Subscription object can no longer be utilized by Subscriber to request more messages.
It is worthwhile mentioning another couple of rules around the same design. These are rules number 2.9 and 2.10 concerning Subscription.request(long n). The rule says that a Subscriber can get the onError signal or the onComplete signal with or without a preceding call to Subscription.request(long n).
- 社交網(wǎng)絡(luò)對齊
- 物聯(lián)網(wǎng)網(wǎng)絡(luò)安全及應(yīng)用
- 異構(gòu)基因共表達網(wǎng)絡(luò)的分析方法
- 物聯(lián)網(wǎng)檢驗檢測技術(shù)
- 物聯(lián)網(wǎng)+BIM:構(gòu)建數(shù)字孿生的未來
- JBoss EAP6 High Availability
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 物聯(lián)網(wǎng)安全技術(shù)
- Socket.IO Real-time Web Application Development
- Wireshark網(wǎng)絡(luò)分析就這么簡單
- 區(qū)塊鏈輕松上手:原理、源碼、搭建與應(yīng)用
- Windows Server 2012 Hyper-V虛擬化管理實踐
- 轉(zhuǎn)化:提升網(wǎng)站流量和轉(zhuǎn)化率的技巧
- Selenium WebDriver 3 Practical Guide
- 工業(yè)以太網(wǎng)技術(shù):AFDX/TTE網(wǎng)絡(luò)原理、接口、互連與安全