在 Quartz Scheduler 中使用 Apache Camel 时出现问题

发布于 2024-11-16 23:38:34 字数 2823 浏览 2 评论 0原文

我是 Apache 骆驼和石英调度程序的新手。我试图将它们两者集成使用,但无法做到这一点。我在“Camel in Action”一书中找到了一篇小文章,但我也没有设法运行该程序 - 这是我的代码

包 com.cockpitconfig.schedulars;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class TestScheduler {

    public static void main(String args[]) throws Exception {
        CamelContext context = new DefaultCamelContext();
        context.disableJMX();
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() {
                from(
                        "quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1")
                        .setBody().simple("Current time is ").to("stream:out");
            }
        });

        context.start();
        Thread.sleep(10000);

        context.stop();
    }
}

但它给出了错误

Exception in thread "main" java.lang.InstantiationError: org.quartz.SimpleTrigger
    at org.apache.camel.component.quartz.QuartzComponent.createEndpoint(QuartzComponent.java:119)
    at org.apache.camel.component.quartz.QuartzComponent.createEndpoint(QuartzComponent.java:54)
    at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:75)
    at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:419)
    at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:47)
    at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:189)
    at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:110)
    at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:116)
    at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:73)
    at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:88)
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:751)
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:174)
    at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:610)
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1514)
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1306)
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1213)
    at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:65)
    at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:52)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1191)
    at com.cockpitconfig.schedulars.TestScheduler.main(TestScheduler.java:24)

有人能解决这个问题吗?

I am new to Apache camel and quartz scheduler. I am trying to to use them both in integration but unable to do it. I found a little article in "Camel in Action" book but I didn't manage to run the program also- here is my code

package com.cockpitconfig.schedulars;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class TestScheduler {

    public static void main(String args[]) throws Exception {
        CamelContext context = new DefaultCamelContext();
        context.disableJMX();
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() {
                from(
                        "quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1")
                        .setBody().simple("Current time is ").to("stream:out");
            }
        });

        context.start();
        Thread.sleep(10000);

        context.stop();
    }
}

But it is giving error

Exception in thread "main" java.lang.InstantiationError: org.quartz.SimpleTrigger
    at org.apache.camel.component.quartz.QuartzComponent.createEndpoint(QuartzComponent.java:119)
    at org.apache.camel.component.quartz.QuartzComponent.createEndpoint(QuartzComponent.java:54)
    at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:75)
    at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:419)
    at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:47)
    at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:189)
    at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:110)
    at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:116)
    at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:73)
    at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:88)
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:751)
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:174)
    at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:610)
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1514)
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1306)
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1213)
    at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:65)
    at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:52)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1191)
    at com.cockpitconfig.schedulars.TestScheduler.main(TestScheduler.java:24)

Does anybody have solution to this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃颗糖壮壮胆 2024-11-23 23:38:34

你使用什么版本的骆驼?使用 2.8-SNAPSHOT 对我来说效果很好。只需确保您的路径中有camel-core、camel-quartz 和camel-stream 依赖项即可。

what version of Camel are you using? it worked fine for me using 2.8-SNAPSHOT. just make sure you have camel-core, camel-quartz and camel-stream dependencies in your path.

金橙橙 2024-11-23 23:38:34

从当前的camel-quartz插件文档来看,这一点并不明显,但从Camel 2.11.0开始,它仅与Quartz 1.x兼容,与Quartz 2.x(已经发布几年了)不兼容,因为Quartz 2.x 与 Spring 3.0 不兼容(Camel 表示暂时将保持 Spring 3.0 兼容性。

这记录在 此 Camel JIRA 问题

It's not obvious from the current camel-quartz plugin docs, but as of Camel 2.11.0 it is only compatible with Quartz 1.x and is NOT compatible with Quartz 2.x (which has been out for a couple of years now) because Quartz 2.x is not compatible with Spring 3.0 (and Camel has said that it will maintain Spring 3.0 compatibility for now.

This is documented on this Camel JIRA issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文