【问题标题】:Using timer with Quartz and Apache Camel在 Quartz 和 Apache Camel 中使用计时器
【发布时间】:2015-04-22 11:40:10
【问题描述】:

我对骆驼和石英有疑问。 我想用 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

有人可以帮我吗?

【问题讨论】:

    标签: java maven apache-camel quartz-scheduler


    【解决方案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
    

    【讨论】:

    • 我试过了,现在我得到了一个相同类型的异常,但原因是“没有找到带有方案的组件:流”,而之前是“没有找到带有方案的组件:石英”。
    • 您正在使用流组件作为端点,您是否也将其导入到 pom.xml 中?添加此处找到的 maven 依赖项:camel.apache.org/stream.html
    • 它运行但现在它不打印时间。它只打印“当前时间是”。
    • 你有没有使用过camelaction的例子,并用石英组件替换了定时器?无论如何,看起来您的间隔定义和标题字段是基于计时器组件而不是石英。阅读以下文档:camel.apache.org/quartz2.html 以获取正确的 URI 和消息头字段
    猜你喜欢
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多