【问题标题】:Camel, get local file with scheduler does not work - camel骆驼,使用调度程序获取本地文件不起作用 - 骆驼
【发布时间】:2020-06-27 22:50:37
【问题描述】:

我有这些依赖项:

<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>

我还添加了这个:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-quartz2</artifactId>
</dependency>

我有一条简单的路线:

      from("file:C:\\dev\\Repository\\ware3\\ff.txt?scheduler=quartz2&scheduler.cron=0/3 0/1 * 1/1 * ? *")
                .routeId("testRoute")
                .log(LoggingLevel.INFO, "******\n*******\n******File asdsaw name : fsa");

它应该每 3 秒调用一次此方法,但我看不到任何带有 **** 或“testroute”的日志。

我想做的是根据石英检查本地文件夹。如果我能成功,我会尝试 FTP,但现在它甚至不能用于本地文件夹。

路径是正确的,因为我可以获取文件

File initialFile = new File("C:\\dev\\Repository\\ware3\\ff.txt");
            InputStream targetStream = null;
            List<String> fileAsLines = null;


            targetStream = new FileInputStream(initialFile);

【问题讨论】:

    标签: spring spring-boot cron apache-camel


    【解决方案1】:

    文件端点语法是:

    file:directoryName[?options]
    

    File Component documentation:

    仅目录

    Camel 仅支持配置了起始目录的端点。所以 directoryName 必须是一个目录。如果您只想使用单个文件,可以使用 fileName 选项,例如通过设置fileName=thefilename

    所以用file:C:\\dev\\Repository\\ware3?fileName=ff.txt&amp;scheduler=...替换file:C:\\dev\\Repository\\ware3\\ff.txt?scheduler=...

    另外,根据您的 Camel 版本,您可能需要将 cron 表达式中的空格替换为 +,例如 scheduler.cron=0/3+0/1+*+1/1+*+?+*。如果您希望文件每 3 秒轮询一次,那么表达式可以简化为 0/3+*+*+*+*+?

    【讨论】:

    • 它以错误due to: No bean could be found in the registry for: 0/3 * * * * ? of type: org.apache.camel.spi.ScheduledPollConsumerScheduler for from("file:C:\\dev\\Repository\\ware3?fileName=ff.txt&amp;scheduler=0/3+*+*+*+*+?") .routeId("asfasafsRoute") .log(LoggingLevel.INFO, "******\n*******\n******File asdsaw name : fsa"); 关闭我想查看日志以了解它是否有效,也许我应该创建一个输出或to
    • 你第一次有正确的调度器选项,为什么你现在修改这个?对于 Camel 2.x 和 camel-quartz2,消费者的最终 uri 应该是 from("file:C:\\dev\\Repository\\ware3?fileName=ff.txt&amp;scheduler=quartz2&amp;scheduler.cron=0/3+*+*+*+*+?")。或者 from("file:C:\\dev\\Repository\\ware3?fileName=ff.txt&amp;scheduler=quartz&amp;scheduler.cron=0/3+*+*+*+*+?") 用于骆驼 3.x 和 camel-quartz
    猜你喜欢
    • 2018-09-09
    • 1970-01-01
    • 2018-09-05
    • 2015-01-23
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    相关资源
    最近更新 更多