Reputation: 41
I have a Camel route that is set to run every five minutes
@Component
public class CamelRoute extends RouteBuilder{
private final String comment = "Cron"
@Override
public void setup() {
from("quartz2://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI")
.log("Processing from"+comment)
.to("activemq:Totally.Rocks");
}
}
And I want to force it to run manually, from Spring http request, and change comment field in CamelRoute
@RequestMapping(value = "/ex/foos", method = RequestMethod.GET)
@ResponseBody
public String getFoosBySimplePath() {
//TODO: Start Camel route
//change camel log "comment" from "Cron" to "HTTP request"
}
Upvotes: 2
Views: 1549
Reputation: 41
Solution for my task was easy, although not straightforward if using Camel documentation:
startRoute(String routeId) Starts the given route if it has been previously stopped
I added another route
from("timer://manualRestart?repeatCount=1")
.routeId("manualRestart")
.noAutoStartup()
.to("activemq:Totally.Rocks");
and use startRoute() to launch it when needed
public String getFoosBySimplePath() {
camelContext.startRoute("manualRestart");
}
Why do I find it "not straightforward"? Because documentation says, that startRoute() can start previously stopped routes. Route was never stopped, it was configured not to start by default.
Upvotes: 2
Reputation: 862
To run a Camel route manually you can use FluentProducerTemplate. You can autowire an instance like a normal bean.
To be honest, I am not sure if it will work with quartz endpoints, but I am sure it is working pretty well with "direct:" endpoints. Anyway, it could be a good start for your findings.
Upvotes: 1