How it works...
In this recipe, we implemented two custom stages. First, we created a custom Source stage. Since a Source emits elements into a stream, we implemented GraphStageLogic with an OutHandler. This handler provides the onPull method that will be called by the downstream stages when there is demand for new elements. In this example, we pushed a string.
Secondly, we created a custom Sink stage. This time, we implemented TimerGraphStageLogic with an InHandler since a Sink receives elements from a stream. TimerGraphStageLogic provides APIs to schedule messages within the stage. To request for more elements from the upstream, we used the pull and grab methods. These methods help consume elements from the stream and manage back pressure. ...
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