Richard Searle

home

Data enrichment "forward" in Akka actor

28 Feb 2012

The Akka  forward operation redirects a message to another actor, with any response flowing back to the originator of the message. This suffices if another actor can better process the message and the original message still suffices to describe the desired operation. This is not always the case:
  1. The second actor might require additional context from the forwarding actor
  2. The forwarding actor might provide data enrichment.
The tell actually accepts a second argument to specify the actor to which the response will be sent. That is normally the entity that invokes the tell operation but can actually be any actor. The tell operation can then be used to send on an augmented message  while retaining the originator actor. The following code provides a (silly) example of how this might be used
case class DataEnrichmentActor extends Actor {
 def receive = {
   case msg ⇒ context.actorFor("/user/second").tell("enrichment"+msg,sender)
 }
}