在 Quartz 和 Apache Camel 中使用计时器
Using timer with Quartz and Apache Camel
我对 Camel 和 quartz 有疑问。
我想用 Quartz 执行一个触发器,所以我写了这个简单的代码,我想在控制台上每两秒打印一次时间:
public class TestQuartz {
public static void main(String args[]) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1").setBody().simple("Current time is ${header.firedTime}").to("stream:out");
}
});
context.start();
Thread.sleep(10000);
context.stop();
}
}
我得到了这个异常:Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[quartz://myGroup/myTimerName?cron=0+0+8+... because of Failed to resolve endpoint: quartz://myGroup/myTimerName?cron=0+0+8+*+*+* due to: No component found with scheme: quartz
我先说我已经在 pom.xml 中插入了依赖项:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz2</artifactId>
<version>${camel.version}</version>
</dependency>
其中 camel.version 是 2.15.1
有人可以帮助我吗?
您在 pom.xml 文件中导入了 camel-quartz2 组件,同时尝试使用旧的石英组件。
石英:http://camel.apache.org/quartz.html
石英2:http://camel.apache.org/quartz2.html
为路线尝试以下 URI:
quartz2://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1
我对 Camel 和 quartz 有疑问。 我想用 Quartz 执行一个触发器,所以我写了这个简单的代码,我想在控制台上每两秒打印一次时间:
public class TestQuartz {
public static void main(String args[]) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1").setBody().simple("Current time is ${header.firedTime}").to("stream:out");
}
});
context.start();
Thread.sleep(10000);
context.stop();
}
}
我得到了这个异常:Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[quartz://myGroup/myTimerName?cron=0+0+8+... because of Failed to resolve endpoint: quartz://myGroup/myTimerName?cron=0+0+8+*+*+* due to: No component found with scheme: quartz
我先说我已经在 pom.xml 中插入了依赖项:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz2</artifactId>
<version>${camel.version}</version>
</dependency>
其中 camel.version 是 2.15.1
有人可以帮助我吗?
您在 pom.xml 文件中导入了 camel-quartz2 组件,同时尝试使用旧的石英组件。
石英:http://camel.apache.org/quartz.html
石英2:http://camel.apache.org/quartz2.html
为路线尝试以下 URI:
quartz2://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1