Reactive programming with reactive streams

Reactive streams (http://www.reactive-streams.org/) define a mechanism to provide asynchronous stream processing with non-blocking back pressure.

Reactive streams are based on the following three elements:

  • A publisher of information
  • One or more subscribers of that information
  • A subscription between the publisher and a consumer

The reactive streams specification determines how these classes should interact among them, according to the following rules:

  • The publisher will add the subscribers that want to be notified
  • The subscriber receives a notification when they're added to a publisher
  • The subscribers request one or more elements from the publisher in an asynchronous way, that is to say, the subscriber requests the element and continues with the execution
  • When the publisher has an element to publish, it sends it to all its subscribers that have requested an element

As we mentioned before, all this communication is asynchronous, so we can take advantage of all the power of our multi-core processor.

Java 9 has included three interfaces, the Flow.Publisher, the Flow.Subscriber, and the Flow.Subscription, and a utility class, the SubmissionPublisher class, to allow us to implement reactive stream applications. In this recipe, you will learn how to use all these elements to implement a basic reactive stream application.

..................Content has been hidden....................

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