How to spawn typed actor

Is there a way to spawn a typed actor outside of actor? Untyped actor system had actorOf function, can’t find any way to spawn a typed actor.



Did you read this chapter of the docs?

Especially the SpawnProtocol section if you want to create actors from “the outside”.

Similarly, is there a way to stop the actors created from “the outside”?

No way to “kill” it, you will have to have a message in the actor protocol that tells it to stop (transition into Behavior.stopped).

Note that there is nothing stopping you from creating your own guardian (or actor you run as a child somewhere) that has different semantics, if you look at the implementation it is quite a simple behavior.

Yes, that is what we did, we have our own guardian that spawns as well as stops.

Just felt that if there is a provision in akka to spawn user actors, there should also be a way to stop them from the outside.

In general it is better to have stopping as a part of the actor protocol to allow for graceful stop rather than dropping all inbox contents (as with context.stop from the parent) so we do not want to encourage that when it is so easy to do yourself if you have decided you really want it.

Makes sense!