Follow these steps to implement the example:
- Create a class named Item that will represent the items of information sent from the publisher to the subscribers. This class has two String attributes, named title and content, and the methods to get() and set() their values. Its source code is very simple, so it won't be included here.
- Then, create a class named Consumer1 and specify that it implements the Subscriber interface parameterized with the Item class. We have to implement four methods. First, we implement the onComplete() method. It simply writes a message to the console:
public class Consumer1 implements Flow.Subscriber<Item> { @Override public void onComplete() { System.out.printf("%s: Consumer 1: Completed\n", ...