Richard Searle's Blog

Thoughts about software

Data enrichment “forward” in Akka actor

Posted by eggsearle on February 28, 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)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: