Lifecycle hooks

The publisher-subscriber communication generates events throughout the lifecycle of a Reactive Stream. Reactor provides corresponding lifecycle methods that can be used to hook custom logic to each of the said events, as shown in the following table:

Subscribe event doOnSubscribe
Request event, for N items from the subscriber doOnRequest
Value event, for all generated values doOnNext
Error event, for any error by the publisher doOnError
Completion event doOnCompletion
Cancel event, for cancellation by the subscriber doOnCancel


In addition to the preceding methods, there are the following methods:

  • doOnEach: This method is executed for all publisher events raised in the stream processing. ...

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.