scala - Akka-Http: How to return a response from an actor? -


i using actor inside request "ask" pattern:

val route =     pathprefix("myapp") {       path("search") {         {           (mainactorref ? dosomething("foo")).mapto[returningtype].map { result =>   complete(httpentity(contenttypes.`application/json`, result ))          }         }       }     } 

the problem main actor communicates other actors , gets answer 1 of actors this:

class mainactor extends actor {    override def receive: receive = {      case d:dosomething =>       anotheractor ! dothis(d)      // received anotheractor reply dothis     case r:dothisresponse =>       // how send response “route”?       pipe (future{r}) ???   }  } 

how can send answer akka-http response?

using "sender()" in main actor doesn't work won't right reference. should pass in dosomething reference use "tell" (!) inside main actor? how pass reference?

use forward instead of tell in the mainactor when sending anotheractor. way anotheractor not "see" mainactor sender .

so, basically, send new messages in intermediate steps forward, actor in line can respond sender, since not see intermediate actors.

edit: complete mainactor

class mainactor extends actor {  override def receive: receive = {     //delegating more work container    case d:dosomething =>      anotheractor forward dothis(d)     // sending response "route"    case r:dothisresponse =>      sender ! response      } } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)