Apache camel 多次使用Camel ConsumerTemplate下载该文件

Apache camel 多次使用Camel ConsumerTemplate下载该文件,apache-camel,jbossfuse,Apache Camel,Jbossfuse,我尝试使用CamelConsumerTemplate多次下载同一文件。它没有被下载多次,但我在使用骆驼路线时完成了下载。 我想使用ConsumerTemplate多次下载文件以下是我正在尝试使用ConsumerTemplate的代码: import org.apache.camel.CamelContext; import org.apache.camel.ConsumerTemplate; import org.apache.camel.Exchange; import org.apache.

我尝试使用CamelConsumerTemplate多次下载同一文件。它没有被下载多次,但我在使用骆驼路线时完成了下载。 我想使用ConsumerTemplate多次下载文件

以下是我正在尝试使用ConsumerTemplate的代码:

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;

    public class DynamicConsumer implements Processor {

        @Override
        public void process(Exchange inExchange) throws Exception {
            CamelContext camelContext = inExchange.getContext();
            ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate();
            String resource = "sftp://tester@localhost:22/myfiles?password=password&noop=true&idempotent=false&readLockMarkerFile=false&readLock=none&filter=#myFileFilter";
            consumerTemplate.start();
            Exchange resourceExchange = consumerTemplate.receive(resource,20000);
            consumerTemplate.stop();
            if(resourceExchange != null) {
                inExchange.getOut().setBody(resourceExchange.getIn().getBody());
                inExchange.getProperties().putAll(resourceExchange.getProperties());
                inExchange.getOut().getHeaders().putAll(resourceExchange.getIn().getHeaders());
            } else {
                inExchange.getOut().setBody(null);
            }
        }
    }
这个动态消费者多次被骆驼路线调用。因此,每次我都希望下载给定位置的文件。但事实并非如此

这里是我用驼峰路线尝试的代码

<from uri="sftp://tester@localhost:22/myfiles?password=password&amp;noop=true&amp;idempotent=false&amp;readLockMarkerFile=false&amp;readLock=none&amp;filter=#myFileFilter"/>

如文档所述,您应该调用ConsumerTemplate的–
doneUoW(Exchange)
函数:

如果您使用了返回交换的任何接收方法 然后,在使用 返回交换

--

尝试在consumerTemplate.stop()之前添加以下内容:


正如文档所述,您应该调用ConsumerTemplate的–
doneUoW(Exchange)
函数:

如果您使用了返回交换的任何接收方法 然后,在使用 返回交换

--

尝试在consumerTemplate.stop()之前添加以下内容:


您是否有
sftp://tester@localhost:22/myfiles?password=password&noop=true&idempotent=false&readLockMarkerFile=false&readLock=none&filter=#myFileFilter“
name/key?@mgyongyos对不起,我在简化代码时出错了。它实际上是从camel exchange中获取另一个指定的属性。现在已更正。您确定该位置上有所需的文件吗?你能公布你的路线吗?另外,您的处理器就像一个内容丰富器,为什么不使用Camel的
pollEnrich(uri)
DSL功能呢?()@mgyongyosi所需文件在该位置可用,并将首次下载该文件。我想按预定的时间间隔触发作业。我想从多个位置下载数据。由于缺乏对动态URI的支持,我没有使用pollRich(直到版本2.16)。我已绑定到版本2.15.1。您是否有
sftp://tester@localhost:22/myfiles?password=password&noop=true&idempotent=false&readLockMarkerFile=false&readLock=none&filter=#myFileFilter“
name/key?@mgyongyos对不起,我在简化代码时出错了。它实际上是从camel exchange中获取另一个指定的属性。现在已更正。您确定该位置上有所需的文件吗?你能公布你的路线吗?另外,您的处理器就像一个内容丰富器,为什么不使用Camel的
pollEnrich(uri)
DSL功能呢?()@mgyongyosi所需文件在该位置可用,并将首次下载该文件。我想按预定的时间间隔触发作业。我想从多个位置下载数据。由于缺乏对动态URI的支持,我没有使用pollRich(直到版本2.16)。我必须使用2.15.1版。
consumerTemplate.doneUoW(resourceExchange);