我需要从 web 服务和 FTP 生成文件到某个位置。
路线1:
from("direct:start")
.routeId("generateFileRoute")
.setHeader(Exchange.HTTP_METHOD, constant("GET"))
.setHeader(Exchange.HTTP_URI, simple(URL))
.setHeader("Authorization", simple(APP_KEY))
.to(URL)
.unmarshal(listJacksonDataFormat)
.marshal(bindyCsvDataFormat)
.to(fileDirLoc + "?fileName=RMA_OUT_${date:now:MMddyyyy_HHmmss}.csv&noop=true");
路由 2:FTP 路由
from("file://"+header("CamelFileNameProduced"))
.routeId("ftpRoute")
.to("sftp://FTP_HOST/DIR?username=???&password=???)
开始路线
Exchange exchange = template.request("direct:start", null);
Object filePathObj = exchange.getIn().getHeader("CamelFileNameProduced");
if (filePathObj != null) { // Makesure Route1 has created the file
camelContext.startRoute("ftpRoute"); // Start FTP route
template.send(exchange); // Send exchange from Route1 to Route2
}
当我在 FTP 路由中硬编码位置时,上面的代码有效。有人可以帮忙吗,我如何通过管道传输这 2 条路由并将 Route 1(“文件名”)的输出传递给 Route2 以进行 FTP?