October 2018
Intermediate to advanced
556 pages
15h 18m
English
Sometimes, it is useful to process a stream not in terms of data, but in terms of signals. To convert a stream of data into a stream of signals and back again, Flux and Mono provide the materialize and dematerialize methods. An example of this is as follows:
Flux.range(1, 3) .doOnNext(e -> log.info("data : {}", e)) .materialize() .doOnNext(e -> log.info("signal: {}", e)) .dematerialize() .collectList() .subscribe(r-> log.info("result: {}", r));
The preceding code produces the following output:
data : 1 signal: onNext(1) data : 2 signal: onNext(2) data : 3 signal: onNext(3) signal: onComplete() result: [1, 2, 3]
Here, when processing the signal stream, the doOnNext method receives not only onNext ...