Skip to content

Instantly share code, notes, and snippets.

@razie
Last active May 5, 2017 20:37
Show Gist options
  • Save razie/6d516e2025ee101fc0facbeaeef6cd96 to your computer and use it in GitHub Desktop.
Save razie/6d516e2025ee101fc0facbeaeef6cd96 to your computer and use it in GitHub Desktop.
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