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

Publisher rules

Publisher has the following interface definition:

  public static interface Publisher<T> { 
public void subscribe(Subscriber<? super T> subscriber);
}

Rule number 1.1 says, the total number of onNext signaled by a Publisher to Subscriber must be less than, or equal to, the total number of elements requested by that Subscriber Subscription at all times. There are multiple facets to this definition here. Let’s try to analyze them one by one:

  • First and foremost, there has to be a request for a message from Subscriber (total number → 1 - N) to Publisher. Therefore, Publisher cannot start sending messages to unsuspecting subscribers on its own as these subscribers might still be deciding when to start receiving messages. Furthermore, some might still be performing some initial tasks in order to start receiving the message.
  • Secondly, only after the request is received by Publisher can it begin transmitting the messages to Subscriber. In response to the request for messages from Publisher, Subscriber receives Subscription. Now Subscriber can use Subscription to interact with Publisher and vice versa. How many messages Publisher should send is mentioned in Subscription so the requested messages by Subscribers should be less than or equal to that number [message count <= total number]
  • Thirdly, Publisher cannot send more messages to Subscriber than requested by Subscriber.

These three points together form a part of the backpressure we mentioned when we began with Reactive Streams.

And yes, the count requested by  Subscriber from Publisher is not binding on Publisher as per the other rule, not binding with respect to the count of messages. Publisher is allowed to send less than the requested count of messages from Subscriber. This can be described with the following.

主站蜘蛛池模板: 团风县| 莆田市| 南平市| 常熟市| 鞍山市| 仁布县| 克山县| 定西市| 隆化县| 衡阳县| 凯里市| 白朗县| 大兴区| 清徐县| 双鸭山市| 班玛县| 泗阳县| 新巴尔虎右旗| 东丽区| 遵化市| 中宁县| 旬邑县| 老河口市| 洪雅县| 崇仁县| 老河口市| 剑川县| 玛纳斯县| 阜阳市| 福州市| 文成县| 邳州市| 宝山区| 高碑店市| 曲阳县| 民丰县| 巫山县| 新乡市| 石台县| 镇沅| 昔阳县|