on demand actor get or else create

后端 未结 4 1954
甜味超标
甜味超标 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:50

    Actors can only be created by their parent, and from your description I assume that you are trying to have the system create a non-toplevel actor, which will always fail. What you should do is to send a message to the parent saying “give me that child here”, then the parent can check whether that currently exists, is in good health, etc., possibly create a new one and then respond with an appropriate result message.

    To reiterate this extremely important point: get-or-create can ONLY ever be done by the direct parent.

提交回复
热议问题