[英]Apache-Camel Choice on Filetype
下面列出的代码可以很好地工作,但是它的功能是查看XML文件,如果该字段是'us',则将其移动到另一个目录。 我想知道有关使用.choice()函数的什么:
1)如何指定要路由的特定文件? (将文件名添加到路径末尾不起作用)
2)如何指定要路由的文件类型? (例如:将所有.txt文件路由到“等等”)
3)除了使用.choice以外,还有其他选择可以帮助我做到这一点吗?
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder()
{
public void configure() throws Exception
{
from("file:C:\\camels\\inner?delete=true")
.choice()
.when(xpath("/author/country = 'us'"))
.to("file:C:\\testing");
}
});
context.start();
Thread.sleep(10000);
context.stop();
这是一些这样做的方法
看看http://camel.apache.org/file-language.html,了解骆驼公开的文件语言,这提供了一些选项,可用于获取扩展名,仅文件名,父文件扩展名等文件名 。
还要查看http://camel.apache.org/file2.html上的include选项,这将有助于仅轮询文件名与正则表达式模式匹配的文件。
from("file:C:\\\\camels\\\\inner?delete=true&include=abc")
建立一个谓词并按如下方式使用它:
CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { Predicate predicate = PredicateBuilder.and(simple("${file:name.ext} == 'txt'"), XPathBuilder.xpath("/author/country = 'us'")); public void configure() throws Exception { from("file:C:\\\\camels\\\\inner?delete=true") .choice() .when(predicate) .to("file:C:\\\\testing"); } }); context.start(); Thread.sleep(10000); context.stop();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.