Materialization

Now we can specify the whole flow for our bakery:

val flow = Boy.shopFlow
.via(Chef.mixFlow)
.via(Cook.formFlow)
.via(bakerFlow)

val graph: RunnableGraph[Future[Done]] = manager.via(flow).toMat(consumer)(Keep.right)

implicit val materializer: Materializer = ActorMaterializer()

graph.run().onComplete(_ => afterAll)

Here, we first construct the full flow by combining sub-flows we defined before. Then we convert the flow to runnable graph by attaching the manager Source and the consumer Sink.

We also specify that we want to keep the right materialized value. The left materialized value would be the result of the stream, which is NotUsed in our case because we just writing produced cookies to the console. The right value is a future which is completed when the flow has finished running and we want to use it to shut down our actor system as soon is it happens.

Finally, we run the graph by bringing an ActorMaterializer in scope and calling the corresponding run method.

Our system runs and bakes tasty cookies, but unfortunately, we forgot to take an important aspect into account: Mixers in our setup are liable to hardware failure.

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

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