How it works...
In this recipe, we created two different streams to count words. We took a different approach here, as compared to the previous recipes. First, we instantiated our Source. Second, we instantiated our Flow stages. As we can see in the code, it is possible to have more than one stage in a Flow, as we saw in wordCountFlow. This Flow is actually a composition of groupBy, map, reduce, and mergeSubstream; however, we can use it now as one stage instead of many. This composing capability allows you to have difficult Flow stages defined as a single unit, and therefore, easy to manage. Last, we instantiated Sink.foreach to print out every element in the stream.
Afterward, we created our two different streams by reusing the stages and ...
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.
Read now
Unlock full access