Hi, I have a use case where I have to pass message between actors and send a response back to the caller. Once I get a request I invoke Actor A, which will do some DB call and return results. But in certain cases actor A has to invoke actor B and get some results from Actor B. It then has to return that result back to the guy who sent the request. I accomplished this by passing a reference to the original sender in the message that I send to actor B as shown below :
App { val actor1 = system.actorOf(A) val actor2 = system.actorOf(B) //I want actor 1 to process this request actor1 ? new Request("process this") } case class HandleSpecialConition(sender : ActorRef) case class SpecialConditionResponse(sender : ActorRef, response: String) A extends Actor { def receive = { case req : Request => { //Checks for special condition and if so sends a message to actor2 and the message is embedded with a reference to the sender to whom we have to respond back if (some_special_condition) { actor2 ! new HandleSpecialCondition(sender) } else { "sending_back_response" } } //when we get the response from Actor B it will contain the reference to the original sender and we reply back to him case response : SpecialConditionResponse => { response.sender ! response.response } } } B extends Actor { def receive = { case m : HandleSpecialCondition { //reply back to actor 1 sender ! new SpecialConditionResponse(m.sender, "Response for special condition") } } } I wanted to ask if there is better way to accomplish this without passing the original sender's reference around. Is there something wrong with this kind of approach. Thanks, Karthik -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.