我正在尝试使用 Apache Camel 从 FTP 服务器下载和路由文件。然而,文件只是偶尔添加到 FTP 服务器,所以让程序连续运行似乎有点过分热情。相反,我宁愿有一个每周运行的 cronjob 并处理已添加到服务器的任何新文件。
一旦不再有任何新文件要处理,有没有办法让 Camel 自动关闭?
我当前的main功能如下所示:
public static void main (String[] args) throws Exception {
org.apache.camel.spring.Main main = new org.apache.camel.spring.Main ();
main.setApplicationContextUri ("applicationContext.xml");
main.enableHangupSupport ();
main.run (args);
}
Run Code Online (Sandbox Code Playgroud)
有趣的部分applicationContext.xml是:
<camelContext>
<route>
<from uri="ftp://ftp.example.com/remoteDir?username=user&password=pass"/>
<to uri="file:../ftp_data?tempPrefix=."/>
</route>
</camelContext>
Run Code Online (Sandbox Code Playgroud)