使用quartz2的Apache Camel Cron作业计划

时间:2020-03-29 10:19:38

标签: apache-camel quartz-scheduler quartz

我的目标是安排每天从星期一到星期五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:在注册表中找不到以下类型的豆:org.apache.camel.spi.ScheduledPollConsumerScheduler 2)我知道计划作业后我的程序应该正在运行。我应该如何确保。我的意思是我需要在设置的时间内运行该程序吗?我应该给 Thread.sleep()中的睡眠值什么? 3)另外,如果无法获取文件,如何使它重试?

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

请帮助解决问题。

1 个答案:

答案 0 :(得分:1)

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

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

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

相关问题