on demand actor get or else create

后端 未结 4 1958
甜味超标
甜味超标 2020-12-15 05:04

I can create actors with actorOf and look them with actorFor. I now want to get an actor by some id:String and if it doesnt exist, I w

4条回答
  •  温柔的废话
    2020-12-15 05:39

    Currently you can use Guice dependency injection with Akka, which is explained at http://www.lightbend.com/activator/template/activator-akka-scala-guice. You have to create an accompanying module for the actor. In its configure method you then need to create a named binding to the actor class and some properties. The properties could come from a configuration where, for example, a router is configured for the actor. You can also put the router configuration in there programmatically. Anywhere you need a reference to the actor you inject it with @Named("actorname"). The configured router will create an actor instance when needed.

提交回复
热议问题