Skip to Content
Hands-On Reactive Programming in Spring 5
book

Hands-On Reactive Programming in Spring 5

by Oleh Dokuka, Igor Lozynskyi
October 2018
Intermediate to advanced
556 pages
15h 18m
English
Packt Publishing
Content preview from Hands-On Reactive Programming in Spring 5

Materializing and dematerializing signals

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Spring Microservices in Action, Second Edition

Spring Microservices in Action, Second Edition

John Carnell, Illary Huaylupo Sanchez

Publisher Resources

ISBN: 9781787284951Supplemental Content