gpt4 book ai didi

java - Camel : pollEnrich and access to the Exchange

转载 作者:行者123 更新时间:2023-11-30 03:21:54 24 4
gpt4 key购买 nike

我有这条路线

from(URI_WEBSERVICE)
.convertBodyTo(Entrada.class)
.process(new ProcessorTratarWS())
.pollEnrich("ftp://10.100.8.2/entradaCamel?username=USER&password=PASSWORD&delete=true&fileName=${property.archivoRespuesta}", timeOut, new EstrategiaConfirmacion())
.to(WS_RESPONDER)

ProcessorTratarWS() 中,我设置了 property.archivoRespuesta 的值,它是 pollEnrich 应下载的文件的名称。

但是,文档显示“PollEnrich 无法访问 Exchange”。这意味着 PollEnrich 无法读取 ${property.archivoRespuesta} 的值

在 Camel 中是否有一些替代方法可以做我正在尝试的同样的事情?

谢谢!

最佳答案

来自http://camel.apache.org/content-enricher.html

... Instead of using enrich you can use Recipient List and have dynamic endpoints and define an AggregationStrategy on the Recipient List which then would work as a enrich would do. ...

尝试这样的事情:

from(URI_WEBSERVICE)
.convertBodyTo(Entrada.class)
.process(new ProcessorTratarWS())
.recipientList(simple("ftp://10.100.8.2/entradaCamel?username=USER&password=PASSWORD&delete=true&fileName=${property.archivoRespuesta}")).aggregationStrategy(new EstrategiaConfirmacion())
.to(WS_RESPONDER)

编辑:

上面的代码是将文件保存到FTP服务器上。如果您想从 FTP 服务器轮询文件,您可以尝试

        from(URI_WEBSERVICE)
.convertBodyTo(Entrada.class)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// logic of ProcessorTratarWS goes here
ConsumerTemplate consumer=exchange.getContext().createConsumerTemplate();
String filename=exchange.getProperty("archivoRespuesta",String.class);
Object file=consumer.receiveBody("ftp://10.100.8.2/entradaCamel?username=USER&password=PASSWORD&delete=true&fileName="+filename,timeOut);
// logic of EstrategiaConfirmacion goes here
}

})
.to(WS_RESPONDER);

免责声明:我没有使用过polling consumer太多了,可能有更优雅/更高效的解决方案

关于java - Camel : pollEnrich and access to the Exchange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31145045/

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