How it works...

In this example, we implemented a reactive streams communication between a publisher and a subscriber using the interfaces provided by the Java 9 API and just followed the expected behavior defined in the reactive streams' specification.

We had a publisher implemented by the MyPublisher class and subscribers implemented by the Consumer class. There are subscriptions between the publishers, and each subscriber is implemented by the MySubscription object.

The cycle of the communication starts when a subscriber calls the subscribe() method of a publisher. The publisher has to create the subscription between them and send that subscription to the subscriber using the onSubscribe() method. The subscriber must use the request() ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.