Is passing around ActorRef to other Actors good or bad ?

前端 未结 2 1435

I\'m trying to figure out if my usage of passing Akka ActorRef around to other actors is not an anti-pattern.

I\'ve a few actors in my system. Some are long

相关标签:
2条回答
  • 2021-02-04 00:30

    There are a couple of good ways to "introduce" actor refs to actor instances that need them.

    1) Create the actor with the refs it needs as constructor args (which is what you are doing)

    2) Pass in the needed refs with a message after the instance is created

    Your solution is perfectly acceptable, and even suggested by Roland Kuhn, the Tech Lead for Akka, in this post:

    Akka actor lookup or dependency injection

    0 讨论(0)
  • 2021-02-04 00:30

    It is perfectly valid, as stated in the Akka API documentation:

    ActorRefs can be freely shared among actors by message passing.

    In your case, you are passing them to the constructors, which is absolutely fine and the way it is supposed to be.

    0 讨论(0)
提交回复
热议问题