如何以自动方式关闭独立的 Apache Camel 应用程序? [英] How can I shutdown a standalone Apache Camel application in an automated way?

查看:27
本文介绍了如何以自动方式关闭独立的 Apache Camel 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Apache Camel 从 FTP 服务器下载和路由文件.然而,文件只是偶尔添加到 FTP 服务器,所以让程序连续运行似乎有点过分热情.相反,我宁愿有一个每周运行的 cronjob 并处理已添加到服务器的任何新文件.

I'm trying to use Apache Camel to download and route files from an FTP server. However, files are only added to the FTP server once in a long while so having the program running continuously seems a bit overzealous. Instead, I would rather have a cronjob that runs weekly and processes any new files that have been added to the server.

有没有办法让 Camel 在不再有任何新文件要处理时自动关闭?

Is there any way to get Camel to automatically shutdown once it no longer has any new files to process?

我当前的 main 函数如下所示:

My current main function looks like this:

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);
}

applicationContext.xml 有趣的部分是:

<camelContext>
    <route>
        <from uri="ftp://ftp.example.com/remoteDir?username=user&amp;password=pass"/>
        <to uri="file:../ftp_data?tempPrefix=."/>
    </route>
</camelContext>

推荐答案

请参阅此常见问题解答如何从路由停止路由:http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html.

See this FAQ how to stop a route from a route: http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html.

然后你可以启用选项:sendEmptyMessageWhenIdle=true,然后在路由中做一个消息过滤,或者基于内容的路由,检测空消息,然后停止路由,然后在那个CamelContext之后.

Then you can enable the option: sendEmptyMessageWhenIdle=true, and then in the route do a message filter, or content based route, and detect the empty message, and then stop the route and then after that CamelContext.

虽然我也认为这个问题之前已经讨论过,所以你可以找到其他 SO 问题或谷歌等.因为还有其他方法可以做到这一点.

Though I also think this question has been discussed before, so you can maybe find other SO questions or google etc. As there is also alternative ways of doing this.

这篇关于如何以自动方式关闭独立的 Apache Camel 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆