Say I materialize an actor inside a Flow
definition from an ActorSource
argument that I passed into the GraphDSL.create()
call. I want to ensure this actor is supervised; it forms an essential part of the service I am building and if it fails without restarting service will be interrupted with no other way of figuring it out. Since it’s materializer by an ActorMaterializer
instance that is itself part of an ActorSystem
, there has to be a way somewhere to supervise this actor and ensure that if it dies, I at least know about it before my users.
Here is the code example:
def webflow() = Flow.fromGraph(GraphDSL.create(actorSource) { implicit builder => source =>
// actor that does stuff and sends info to the actor inside "source"
val actorSink = builder.add(ActorSink.actorRef[Protocol](
ref = ref,
onCompleteMessage = Disconnected,
onFailureMessage = Failed.apply
)
)
// materialized value - I want to watch this!
val actorSource = builder.materializedValue.map(ref => Register(ref))
// now the data can be fed back to the stream
actorSource ~> actorSink
// define more component, expose ports
....
}
)