gpt4 book ai didi

java - Apache Camel |文件传输协议(protocol) |仅使用单个文件

转载 作者:行者123 更新时间:2023-11-30 09:32:17 26 4
gpt4 key购买 nike

我正在尝试读取 ftp 目录中的所有文本文件,并解析它们。如果解析成功,则将它们移动到不同的目录(不是默认目录,即 .done 目录),如果解析失败,则文件应保留在 ftp 目录中。这个概念看起来很简单,但是我的路由只从 ftp 读取一个文件,并且路由在获取一个文件后自行结束。

代码如下:

@Override
public void configure() throws Exception {

from(EndPointConstants.DIRECT + GetDriverProductInfo.class.getSimpleName())
.pollEnrich(ftp://ingestion_user@10.207.6.42/fantics?password=******&recursive=true)
.to("file://test/readFile")

它是否与 pollEnrich 相关,它只能获取单个文件并且该过程不会递归发生?

最佳答案

If the parsing is successful, then move them to a different directory(not the default one i.e. .done directory)

使用像这样的例子:

.to("file://test/readFile?autoCreate=true&moveFailed=.failed/${date:now:yyyyMMdd}/${file:name}&move=.processed/${date:now:dd-MM-yyyy}/${file:name}")

来自 Camel 文档 ( FTP/SFTP/FTPS Component ):

The FTP consumer will by default leave the consumed files untouched on the remote FTP server. You have to configure it explicitly if you want it to delete the files or move them to another location. For example you can use delete=true to delete the files, or use move=.done to move the files into a hidden done sub directory. The regular File consumer is different as it will by default move files to a .camel sub directory. The reason Camel does not do this by default for the FTP consumer is that it may lack permissions by default to be able to move or delete files.

所以你可以使用例如:

&noop=false

&move

&delete=false

编辑:

我认为您应该想出类似这样的东西(以下代码),因为 pollEnrich() 不适合这种情况。

(强烈建议不要按原样使用以下代码,而不是使用示例)

from("direct:scan")
.process(new Processor()
{
public void process(Exchange exchange) throws Exception
{
ConsumerTemplate consumerTemplate = exchange.getContext().createConsumerTemplate();
ProducerTemplate producerTemplate = exchange.getContext().createProducerTemplate();
producerTemplate.setDefaultEndpointUri("file:..");
producerTemplate.send(consumerTemplate.receive("ftp:.."));
}
});

干杯!

关于java - Apache Camel |文件传输协议(protocol) |仅使用单个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12559983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com