Skip to content

Instantly share code, notes, and snippets.

@razie

razie/SampleActor34.scala

Last active May 5, 2017
Embed
What would you like to do?
import akka.actor.{Actor, Props}
import play.libs.Akka
object Sample {
case class MsgNotify()
case class MsgFindOrder(orderId: String)
case class MsgOrderFound(order: {def accountId: String})
case class MsgFindAccount(accountId: String)
case class MsgAccountFound(account: {def email:String})
case class MsgSend(email: String, message: String)
class SomeDbActor extends Actor {
def receive = { case _ => {} }
}
class SomeEmailActor extends Actor {
def receive = { case _ => {} }
}
class MyActor(orderId:String, notification:String) extends Actor {
val db = Akka.system.actorOf(Props(new SomeDbActor()))
val email = Akka.system.actorOf(Props(new SomeEmailActor()))
def receive = {
case MsgNotify => db ! MsgFindOrder(orderId)
case MsgOrderFound(order) => db ! MsgFindAccount(order.accountId)
case MsgAccountFound(account) => email ! MsgSend(account.email, notification)
}
}
def notify(orderId: String, notification: String) = {
val a = Akka.system.actorOf(Props(new MyActor(orderId, notification)))
a ! new MsgNotify
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.