Created
January 13, 2013 00:18
-
-
Save raulraja/4521203 to your computer and use it in GitHub Desktop.
scala EmailService Actor
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
package services | |
import akka.actor.Actor._ | |
import com.typesafe.plugin._ | |
import akka.actor.{Props, OneForOneStrategy, Actor} | |
import play.api.libs.concurrent.Akka | |
import play.api.Play.current | |
case class EmailMessage(subject: String, recipient: String, from: String, text: String, html: String) | |
object EmailService { | |
val emailServiceActor = Akka.system.actorOf(Props[EmailService], name = "emailServiceActor") | |
def send(emailMessage: EmailMessage) { | |
emailServiceActor ! emailMessage | |
} | |
private def sendEmailSync(emailMessage: EmailMessage) { | |
use[MailerPlugin].email | |
.setSubject(emailMessage.subject) | |
.addRecipient(emailMessage.recipient) | |
.addFrom(emailMessage.from) | |
.send(emailMessage.text, emailMessage.html) | |
} | |
} | |
class EmailService extends Actor { | |
protected def receive = { | |
case email: EmailMessage => { | |
println("Before sending mail") | |
EmailService.sendEmailSync(email) | |
println("After sending mail") | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment