Akka actorFor vs passing an ActorRef

后端 未结 1 524
长发绾君心
长发绾君心 2021-02-19 02:51

I\'m learning Akka and I\'m trying to figure out how to get actors talking to each other (let\'s call them A and B). It\'s not a request / response sce

1条回答
  •  南方客
    南方客 (楼主)
    2021-02-19 03:23

    In my humble opinion you have three strategies, which I list from the closer to your problem (but also to me the worst pattern, I am sorry)

    Strategy 1: you create actor A and actor B, passing actorRef A to the constructor of actor B. Your ping-pong will start from actor B sending a message to actor A, and actor A can simply reply using the sender reference. (or the other way around)


    Strategy 2: you create a layer in your application which takes care of the naming: it assigns the name at creation of the actor, as well as when querying. This centralizes the problem in a single point.


    Strategy 3: You wonder if two siblings actors playing ping-pong are not replacing a better, more modular actor hierarchy where basically each actor communicate only with his parent and his children and has no knowledge about his siblings.

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