I have a Db of Quartz CronTriggers. I want to port this entire system to an Akka based backend I am architecting currently. I was looking at and thinking about ways this can be done.
For instance, CustomRouteBuilders and other similar stuff. I tried the excellent Quartz-Camel-Akka integration example by Giovani and was quite impressed with it. Now, I have multiple cron triggers in my system with different and user created cron expressions.
How can I program a system of Camel Consumer Actors with such user dependent endpointUri's? Was thinking of many options but could not figure out anything yet.
Please help me in this endeavor. I am also open to other ideas beyond Quartz and Camel. I want to stick to Akka based backend platform. My system consists of user defined jobs that fire at user defined cron formable timings.
Starting from a list of cron expressions (e.g. read from database) you could iterate over the list and start a quartz consumer actor for each element. Here's an example:
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
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With