Send payload while sending message to an akka actor

182 Views Asked by At

Is there a way to add some kind of payload (attached message) while sending a message to an akka actor? I know there is a way to do this using routers, but can this be achieved by simple message passing?

By simple message passing, I mean something like this remoteActor ! "hi".

1

There are 1 best solutions below

0
Haito On

Yes, yes you can. You can send any payload you want but it has to be immutable (as far as i know). Most of people use case class-es. For example.

case class Payload(pay: List[String], load: Int)

then you can do as follows

actorRef ! Payload(List("string1","1gnirts"),69)

but you hve to remember to create appropriate case in receive

def receive = 
   case Payload(pay,load) => doSomeStuff(load,pay)