Phase IV¶
Send Email (Bread-Project Dependency)¶
- Notification by email is already available in Bread project, we need to import Bread, and actually send the mail.
- Edit Lottery.ksmile
import-component bread-release-0.4(NotifierProcess)
process-module LotteryProcess(LotteryReadMongo, LotteryStream,NotifierProcess) at com.metastay.lotteryprocess
- $add-component bread-release-0.4,follow the guided steps(if any)
- $smile
- Edit WinnerEmailSenderProcessorCode.scala
override def process(event: com.metastay.lotterystream.stream.LotteryRan): Unit = {
val winner = event.winner
val email = ParticipantQuery().name.is(winner).findOne.get.email
val body = s"Congratulation $winner,You have won the Lottery $event.lotteryName!!"
val message = com.metastay.notifierprocess.message.SendMailMessage(toList = email, subject = "Won Lottery", body = body)
grab[SmileAsyncService].publish(message)
}
- $run
- Test through curl
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”,”amount”:1000}’ http://localhost:9000/api/lottery/create-lottery
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”,”participantName”:”John”}’ http://localhost:9000/api/lottery/ add-participant
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”,”participantName”:”Jim”}’ http://localhost:9000/api/lottery/add-participant
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”,”participantName”:”Joe”}’ http://localhost:9000/api/lottery/add-participant
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”}’ http://localhost:9000/api/lottery/run
Processor¶
- Edit Lottery.ksmile
process-module LotteryProcess(LotteryReadMongo, LotteryStream) at com.metastay.lotteryprocess
- $smile
- Edit LotteryProcess.kprocess, in eclipse
processor WinnerEmailSender {
subscribe event-ref LotteryStream::LotteryRan
}
- $compile
- Edit WinnerEmailSenderProcessorCode.scala
override def process(event: com.metastay.lotterystream.stream.LotteryRan): Unit = {
val winner = event.winner
val email = ParticipantQuery().name.is(winner).findOne.get.email
println(s"Congratulation $winner, you have won the lottery ${event.lotteryName}; mail to $email ")
}
- $run
- Test through curl
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”,”amount”:1000}’ http://localhost:9000/api/lottery/create-lottery
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”,”participantName”:”John”}’ http://localhost:9000/api/lottery/ add-participant
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”,”participantName”:”Jim”}’ http://localhost:9000/api/lottery/add-participant
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”,”participantName”:”Joe”}’ http://localhost:9000/api/lottery/add-participant
- curl -H “Content-Type: application/json” -X POST -d ‘{“lotteryName”:”DLoto”}’ http://localhost:9000/api/lottery/run