我有一条看起来像这样的 Camel 路线:
public class CamelReaderRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("quartz://myjob?cron=0+0/5+*+*+*+?")
//....(some more content)
.routeId("MyCamelRoute");
}
基本上 Quartz 每五分钟“触发”一次路由。当对该路由进行单元测试时,它不会触发,除非时间正好是 00:00 或 00:05 或 00:10 等等。
那么如何更改“from”中使用的端点以便立即触发路由? 到目前为止,这是我的测试课:
public class CamelRouteTest extends CamelTestSupport {
@Test
public void shall_run_the_route_or_something() {
context.getRouteDefinition("MyCamelRoute")
.adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
//something should be done here?
}
});
我可以看到,在 Camel 2.9 中,我可以在我的配置方法中使用 replaceFromWith,但是由于依赖关系等等,我只能使用 Camel 2.8。他们在 2.9 之前有任何形式的 replaceFromWith 吗?
最佳答案
有几个选项,一个是将 quartz “fireNow=true”选项设置为在路由启动时调用(尽管它在部署时也会这样做)。否则,只需打散 quartz 路由,以便可以直接调用处理...
from("quartz://myjob?cron=0+0/5+*+*+*+?")
.to("direct:process");
from("direct:process")...
然后在你的单元测试中...调用直接路由等
template.sendBody("direct:process",null);
关于java - Apache Camel 中 Quartz cron 作业的测试路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9294479/