scala - Akka Actors 中的 Quartz CronTriggers 使用还是不使用 Camel?

标签 scala cron quartz-scheduler apache-camel akka

我有一个 Quartz CronTriggers 数据库。我想将整个系统移植到我目前正在构建的基于 Akka 的后端。我正在研究并思考如何做到这一点。

例如,CustomRouteBuilders 和其他类似的东西。我尝试了 Giovani 出色的 Quartz-Camel-Akka 集成示例,并对其印象深刻。现在,我的系统中有多个 cron 触发器,它们具有不同的和用户创建的 cron 表达式。

我如何使用这种依赖于用户的 endpointUri 对 Camel Consumer Actors 系统进行编程?想了很多选择,但什么也想不出来。

请帮助我完成这项工作。我也对 Quartz 和 Camel 以外的其他想法持开放态度。我想坚持使用基于 Akka 的后端平台。我的系统由用户定义的作业组成,这些作业以用户定义的 cron 可成形时间触发。

最佳答案

从 cron 表达式列表(例如从数据库读取)开始,您可以遍历列表并为每个元素启动一个 quartz 消费者角色。下面是一个例子:

import akka.actor.Actor
import akka.actor.Actor._
import akka.camel.CamelServiceManager._
import akka.camel.Consumer

object CronExample {

  def main(args: Array[String]) {
    val cronExpressions: List[String] = ... // cron expressions read from database

    startCamelService

    cronExpressions foreach { cronExpression =>
      val timerName: String = ... // app-specific timer name for cronExpression
      actorOf(new Scheduler(timerName, cronExpression)).start
    }
  }

  class Scheduler(timerName: String, cronExpression: String) extends Actor with Consumer {
    def endpointUri = "quartz://%s?cron=%s" format (timerName, cronExpression)

    protected def receive = {
      case msg => ... // react on timer event
    }
  }
}

关于scala - Akka Actors 中的 Quartz CronTriggers 使用还是不使用 Camel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6758597/

相关文章:

Scala 命名参数

Python 写入文件在手动完成时工作正常,但 cron 失败

linux cron 作业没有运行

php - 并行执行多个 php 脚本

spring - 使用 Spring Batch 或 Quartz 调度程序来调度作业

使用::for 列表的 scala 匹配案例

scala - 为什么 scala 的集合默认不是 'views'?

java - scala/java 是否有类似 Python 中的 StringIO 的东西?

tomcat - 在 Grails 中制作 WAR 文件

java - Spring无法在实现Quartz Job的类中注入(inject)Bean