Processors

The Reactive Streams specification defines the Processor interface. A Processor is a Publisher and a Subscriber at the same time. So, we can subscribe to a Processor instance and also manually send signals (onNext, onError, onComplete) to it. The authors of Reactor recommend omitting processors as they are hard to use and are prone to errors. In most cases, provided processors may be superseded by a combination of operators. Alternatively, a generator factory method (push, create, generate) may fit better for adapting external APIs.

Reactor proposes the following kinds of processors:

  • Direct processors can only push data through manual user actions by operating with the processor's sink. DirectProcessor and UnicastProcessor are representatives of this group of processors. DirectProcessor does not handle backpressure but may be used to publish events to multiple subscribers.  UnicastProcessor handles backpressure with an internal queue, however, may serve one Subscriberat most.
  • Synchronous processors (EmitterProcessor and ReplayProcessor) may push data both manually and by subscribing to an upstream Publisher. EmitterProcessor may serve multiple subscribers and honor their demands, but may consume data only from one Publisher and in a synchronous manner. ReplayProcessor behaves similarly to EmitterProcessor, however, allows a couple of strategies for caching incoming data.
  • Asynchronous processors (WorkQueueProcessor and TopicProcessor) can push downstream data obtained from multiple upstream publishers. To deal with multiple upstream publishers, these processors use the RingBuffer data structure. These processors have a dedicated builder API because the number of configuration options makes it hard to initialize them. TopicProcessor is Reactive Streams compliant and associates a Thread for each downstream Subscriber to handle interactions there. Consequently, there is a limit to how many downstream subscribers it can serve. WorkQueueProcessor has characteristics similar to TopicProcessor. However, it relaxes some of the Reactive Streams' requirements, which allows a reduction in the size of resources it uses at runtime.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.70.247