Scala Akka Http:如何返回参与者的响应?
我在一个请求中使用了一个actor,并使用了“ask”模式: 问题在于,主要参与者与其他参与者进行交流,并从其中一个参与者那里得到如下回答:Scala Akka Http:如何返回参与者的响应?,scala,akka,akka-http,Scala,Akka,Akka Http,我在一个请求中使用了一个actor,并使用了“ask”模式: 问题在于,主要参与者与其他参与者进行交流,并从其中一个参与者那里得到如下回答: class MainActor extends Actor { override def receive: Receive = { case d:DoSomething => anotherActor ! DoThis(d) // received from anotherActor as reply to Do
class MainActor extends Actor {
override def receive: Receive = {
case d:DoSomething =>
anotherActor ! DoThis(d)
// received from anotherActor as reply to DoThis
case r:DoThisResponse =>
// how do I send the response back to my “route”?
pipe (Future{r}) to ???
}
}
如何将此答案作为响应发送回Akka Http
在主参与者中使用“sender()”无效,因为它不是正确的引用。我是否应该在主要演员的DoSomething
中传递一些与“tell”(!)一起使用的参考资料?如何传递此引用?当发送到其他参与者时,在主参与者
中使用而不是告诉
。这样,另一个参与者
将不会“看到”main参与者
作为发送者
因此,基本上,您可以在中间步骤中使用forward
发送新消息,但是行中的参与者可以简单地响应sender
,因为它看不到中间参与者
编辑:一个完整的main参与者
class MainActor extends Actor {
override def receive: Receive = {
//delegating some more work to another container
case d:DoSomething =>
anotherActor forward DoThis(d)
// sending a response back to "route"
case r:DoThisResponse =>
sender ! Response
}
}
我试过了,但没用。我不知道如何使用forward。奇怪。当使用forward时会发生什么?没有什么,比如在DoSomething中,forward触发另一个参与者的某个东西,在某个点上会发送Dothis响应。好的,我将编写一个完整的Main参与者。我做了和你一样的事情,它不起作用。发送者将是向您发送“DoThisResponse”的另一个参与者。我甚至尝试删除case dothis response,并在发送人转发的otheractor中直接回复,但没有成功
class MainActor extends Actor {
override def receive: Receive = {
//delegating some more work to another container
case d:DoSomething =>
anotherActor forward DoThis(d)
// sending a response back to "route"
case r:DoThisResponse =>
sender ! Response
}
}