我正在开发一个简单的项目,它可以启动PhantomJS进程并通过WebSockets与之通信。我在我的控制器中宣布了经理演员和ws动作:
class Application @Inject()(implicit actorSystem: ActorSystem, materializer: Materializer) extends Controller {
val manager = actorSystem.actorOf(Manager.props, "manager")
def index = Action {
Ok(views.html.main())
}
def socket = WebSocket.accept[String, String] { request =>
ActorFlow.actorRef(out => WebSocketAccepter.props(out, manager))
}
def start = Action {
manager ! "START"
Ok
}
Manager actor只是启动PhantomJS,它连接到WS。
一切正常,我从PhantomJS得到了开场白的消息,但接下来我想从经理那里获取一些信息并将其归还给PhantomJS:
class WebSocketAccepter(out: ActorRef, manager: ActorRef) extends Actor with ActorLogging {
...
def receive = {
case message: String => {
val json = Json.parse(message)
val messageType: String = (json \ "type").as[String]
messageType match {
case "OPEN" => {
(manager ? AskInfo).mapTo[RegInfo].map(info => {
out ! Json.toJson(info).toString()
})
}
...
}
我将经理演员作为参数传递,但当我询问信息时说:
a.a.RepointableActorRef - Message [models.AskInfo$] from Actor[akka://application/temp/$a]
to Actor[akka://application/user/manager#-1822927709] was not delivered.
[1] dead letters encountered.
这有点奇怪,websocket演员走在临时路径下。有什么问题?
答案 0 :(得分:0)
通过从ManagerActor向特殊子actor
中取出启动流程代码解决了这个问题