我正在尝试确定将Akka ActorRef
传递给其他actor的用法是否不是反模式。
我的系统中有一些actor。其中一些是长期存在的 (restClientRouter
,publisher
),而有些在完成工作后就消失了 (geoActor
)。短期存在的actors需要向长期存在的actors发送消息,因此需要它们的ActorRef
。
//router for a bunch of other actors
val restClientRouter = createRouter(context.system)
//publishers messages to an output message queue
val publisher: ActorRef = context.actorOf(Props(new PublisherActor(host, channel)), name = "pub-actor")
//this actor send a message to the restClientRouter and then sends the response
//to the publisher
val geoActor = context.actorOf(Props(new GeoInferenceActor(restClientRouter, publisher)), name = "geo-inference-actor")
你可以看到我正在将ActorRefs (restClientRouter
和 publisher
) 传递给GeoInferenceActor
的构造函数。这样做可以吗?是否有更好的方法?