An introduction to processors

A processor represents a state of data processing. It is therefore presented as both a publisher and a subscriber. Since it is a publisher, we can create a processor and Subscribe to it. Most of the functions of a publisher can be performed using a processor; it can inject custom data, as well as generate errors and completion events. We can also interface all operators on it.

Consider the following code:

DirectProcessor<Long> data = DirectProcessor.create();data.take(2).subscribe(t -> System.out.println(t));data.onNext(10L);data.onNext(11L);data.onNext(12L);

In the preceding code, we did the following things:

  1. We added an instance of DirectProcessor
  2. In the second line, we added the take operator, to select two ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.