Reputation: 9
I started learning akka from https://doc.akka.io/docs/akka/current/index.html
I have ActorSystem with child actors and all child actors created in the hierarchy with parent actor. For an example : DeviceManager is my parent actor and device is child actor.
I would like to understand where akka stream flow kick off in actor lifecycle. When we create parent actor or when stream process will start?
How Akka stream is correlated with Actor lifecycle?
Upvotes: 0
Views: 302
Reputation: 4800
How Akka stream is correlated with Actor lifecycle?
Akka Streams and the Typed Actor API are essentially two separate APIs that can interoperate and share some implementation details. The lifecycle of any actors you create with the Actor API are completely independent of any streams you are running. (And vice versa.)
I would like to understand where akka stream flow kick off in actor lifecycle, when we create parent actor when stream process will start?
As mentioned above, streams are independent. A stream (represented as a RunnableGraph
) is going to "kick off" when you run
it. (Not that there are several convenience methods to do the same thing such as Source.runWith
, Source.runForeach
, and many more. Any streams method with "run" is likely to "kick off" a stream.) This "kicking off" is called materialization, wherein your graph (composed of sources, flows, and sinks), which is just a blueprint for a stream, is brought into being.
A good place to start learning is the streams quickstart.
I have ActorSystem with child actors and all child actors created in the hierarchy with parent actor. DeviceManager is my parent actor and device is child actor.
If you want to have the two interoperate, take a look at the Actor Interop section of the Akka Streams documentation. But as an example, if you have a stream of IoT data that you are processing in an Akka Stream, and at the end of the stream you want to send the elements of that stream to your DeviceManager actor, you could do that with an ActorSink.actorRefWithBackpressure
. You just use that Sink at the end of your stream and then your actor will receive normal actor messages. (If you don't need the backpressure, you can just use ActorSink.actorRef
, but if you are using Streams you should use backpressure.)
Upvotes: 1