Apache camel cron 错误,因为无法解析端点:cron

Apache camel cron error because of Failed to resolve endpoint: cron

我尝试将 camel 与 cron 表达式一起使用。因为我需要 3 个不同的事情来处理 cron 表达式,3 个不同的时间。远程文件的每日、每月和即时检查。我不能用 spring 批处理。所以,我选择了骆驼。

@Override
public void configure() throws Exception {

    onException(Exception.class)
        .process(lifeDispatchExceptionProcessor)
        .handled(true)
        .transform()
        .simple("Error reported: ${exception.message} - cannot process this message.");

    from("cron:tab?schedule=0/3 0/1 * 1/1 * ? *")
        .setBody().constant("event")
        .log("${body} faafs")
        .process(documentProcessor);
    
}

我将此方法添加为 hello world,但即使这样也不起作用:

//org.apache.camel.spring.boot.CamelSpringBootInitializationException: org.apache.camel.FailedToCreateRouteException: // Failed to create route route147: Route(route147)[[From[cron:tab?schedule=0/3 0/1 * 1/1

  • ? ]... // because of Failed to resolve endpoint: cron://tab?schedule=0%2F3+0%2F1++1%2F1++%3F+ due to: No component found with scheme: cron

这是pom.xml:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>jaxp-ri</artifactId>
            <groupId>com.sun.xml.parsers</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-quartz2</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>jaxp-ri</artifactId>
            <groupId>com.sun.xml.parsers</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jackson</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>jaxp-ri</artifactId>
            <groupId>com.sun.xml.parsers</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jms</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>jaxp-ri</artifactId>
            <groupId>com.sun.xml.parsers</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-ftp</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>jaxp-ri</artifactId>
            <groupId>com.sun.xml.parsers</groupId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-bindy</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-crypto</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>2.18.1</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-kafka</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>jaxp-ri</artifactId>
            <groupId>com.sun.xml.parsers</groupId>
        </exclusion>
    </exclusions>
</dependency>

我希望能够使用 cron 表达式,所以 camel 会根据 cron 表达式进行检查。有帮助吗?

来自 Cron Components 的 Camel Doc,您必须在使用前注入依赖项 camel-cron

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-cron</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>

Camel 3.1 版本后可用的 cron 组件。对于 3.1 之前的版本,您可以考虑使用 the cron trigger method under quartz2 component.