Last active
May 5, 2017 20:37
-
-
Save razie/6d516e2025ee101fc0facbeaeef6cd96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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