Hi everyone,

I'm looking for some advice. I have an actor whose state needs to be 
updated via a HTTP request. I'm using Akka HTTP with the Route DSL and an 
Ask pattern (this seems to be 'normal')

onComplete(*broker ?* *UpdateCommand*(id, "something")) {
    case *Success*(u) => *complete*("updated")
    case _                => *complete*("An error has occured")
}

So an update message is sent to a broker as an 'Ask' so the result can be 
returned in the Http response. The broker locates the actor that needs to 
be updated based on the id passed in from the request and message. So the 
broker needs to forward the Ask on to the target, I know I can do this with 
a PipeTo - but I would also like the broker to receive the response so it 
can cache some data. So I guess i'm trying to Tee the response, sending it 
to myself and back to the original sender.

This is what I have now and it feels nasty:

def receive = {
    case update: UpdateCommand =>
      val originalSender = sender      # capture the original sender of the 
Ask, since we need to reply in a future continuation
      val targetActor = actors.getOrElse(update.id, throw new 
RuntimeException("not available"))
      targetActor.ask(update) onSuccess {
        case result => {
          originalSender ! result      # respond to the original ask
          self.tell(result, targetActor)  # tell it to ourself, but preseve 
the fact it came from endActor
        }
      }

I'm pretty new to Akka and these patterns. Is there a nice way to do this? 
Maybe using a pipeTo somehow, or some other combination of functions? Do 
other people do this kind of thing

Any tips appreciated
Ian

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to