首页 > 解决方案 > Apache Camel Cron 作业调度与quartz2

问题描述

我的目标是从周一到周五每天 15:00 安排一份工作。下面是我的代码:

CamelContext _ctx = new DefaultCamelContext();
_ctx.addRoutes(new RouteBuilder() {

            public void configure() throws Exception {
from("ftp://Sid@localhost:21/equityFeedsProcessing/?password=sid#ftp&stepwise=false&useList=false&ignoreFileNotFoundOrPermissionError=true&fileName=data-sample.csv&"
                        + "scheduler=quartz2&scheduler.cron=00+15+*+*+MON-FRI")
          .to("file:src/main/resources/?fileName=abc.csv");

            }

        });

        _ctx.start();
         Thread.sleep(30000);
        _ctx.stop();

问题:1)我遇到一个非常奇怪的异常: 原因:org.apache.camel.NoSuchBeanException:在注册表中找不到 bean:quartz2 类型:org.apache.camel.spi.ScheduledPollConsumerScheduler 2)我明白我的程序应该在安排作业时运行。我应该如何确保。我的意思是我需要在我设置的时间内运行这个程序吗?我应该为Thread.sleep()中的睡眠赋予什么价值?3)如果它无法获取文件,我怎样才能让它重试?

请注意:除调度程序外,我的程序运行良好,即它能够从 FTP 服务器获取文件并下载到我的本地位置。

请帮助解决问题。

标签: apache-camelquartz-schedulerquartz

解决方案


您可以每天在特定时刻启动骆驼上下文。但是为什么不总是运行它(所以需要 Thread.sleep)

有关重试机制,请参阅https://camel.apache.org/manual/latest/faq/how-do-i-handle-failures-when-sumption-for-example-from-a-ftp-server.html

奇怪的异常可能是由于缺少一些类路径问题


推荐阅读