我想在我的Play 2.0(使用java)框架应用程序中使用akka的调度程序来发送特定日期和时间的电子邮件提醒。我是2.0的新手。如果有人知道(详细),请告诉我在play 2.0框架中使用akka调度程序的程序? 提前谢谢。
答案 0 :(得分:3)
我也是新手,还有另一个与Scala中的Akka有关的问题。但在阅读时我发现这可能对您有所帮助:http://www.playframework.org/documentation/2.0/JavaAkka也许这也是:https://github.com/playframework/Play20/wiki/JavaAsync
答案 1 :(得分:0)
模块类
import com.google.inject.AbstractModule
import play.api.libs.concurrent.AkkaGuiceSupport
class JobModule extends AbstractModule with AkkaGuiceSupport {
def configure() = {
bindActor[JobBucket]("job-bucket-actor")
bind(classOf[Scheduler]).asEagerSingleton()
}
}
计划程序类
import javax.inject._
import akka.actor._
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
class Scheduler @Inject()(val system: ActorSystem, @Named("job-bucket-actor") val jobBucketActor: ActorRef)(implicit ec: ExecutionContext) {
system.scheduler.schedule(0.microseconds, 1.day, jobBucketActor, "cleanBucket")
}
JobBucket (您可以在此类中创建多个作业,并通过将不同的消息传递给receive方法来调用它们。)
import javax.inject._
import akka.actor.Actor
import org.apache.commons.io.FileUtils
import play.api.Logger
// You can inject any service class or other class if it's required
@Singleton
class JobBucket extends Actor {
def receive = {
//You can place n number of cases.
case "cleanBucket" => clean()
}
def clean(): Unit = {
//Do whatever you want to do over here.
Logger.info("This task has been scheduled...!!!")
}
}
您还需要在apllication.config文件中添加一行: play.modules.enabled + =" com.abc.xyz.JobModule"