I am using an actor inside a request with the "ask" pattern:
val route =
pathPrefix("myapp") {
path("search") {
get {
(mainActorRef ? DoSomething("foo")).mapTo[ReturningType].map { result =>
complete(HttpEntity(ContentTypes.`application/json`, result ))
}
}
}
}
The problem is that the main actor communicates with other actors and gets an answer back from one of those actors like this:
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 ???
}
}
How can I send this answer back to Akka-Http as response?
Using "sender()" in the main actor doesn't work as it won't be the right reference. Should I pass in the DoSomething some reference to use with "tell" (!) inside the main actor? How do I pass this reference?