骆驼sftp生产商。如何从单个处理器将多个文件放入不同的 sftp 文件夹
Camel sftp producer. How to put multiple files to different sftp folders from single processor
我使用 DSL 配置和 spring。
我的路线是这样的:
@Component
public class UploadRoutesDefinition extends RouteBuilder {
@Override
public void configure() throws Exception {
from("seda:rest_upload")
.process(new Processor() {
@Override
public void process(Exchange exchange) {
...
String sftPathForAdditionalFile = ....
String AdditionalFileContent = ...
...
}
).to(String.format(SFTP_BASE_URL,systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath(),
systemSettingsService.getSystemSettings().getSftpPassword()))
它允许我从 seda:rest_upload
读取文件,然后将其移动到 sftp 文件夹。
我想再移动一个文件。我知道 process
方法中的路径和内容。
如何实现?
更新
我当前的代码;
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("CamelFilename", "ololo.txt");
exchange.getIn().setBody(exchange.getProperty(PUSH_ERROR_MESSAGE, String.class).getBytes());
exchange.getIn().setHeader("destFilePath", sftpErrorFileTextPath);
}
})
.to(String.format(SFTP_BASE_URL + "&fileExist=Append",
systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
"${header.destFilePath}",
systemSettingsService.getSystemSettings().getSftpPassword()))
.end();
这是一种方法,
@Override
public void configure() throws Exception {
from("seda:rest_upload")
.multicast()
.to("direct::sendMainFile")
.to("direct:sendAnotherFile") // You could also use seda:
.end();
from("direct:sendMainFile")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String filepath = <calculate filepath>;
String completeFilePath = systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath() + filepath
exchange.getIn().setHeader("destFilePath", completeFilePath);
exchange.getIn().setHeader("CamelFileName", fileNameforMainFile);
}
}.toD(sftpRoute()) // It is toD not to
from("direct:sendAnotherfile")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// Here you have the same body which was sent from rest_upload
// extract the info from exchange.getIn().getBody()
// Read the file and set it as exchange body
String fileContent = <Your logic to read file>
exchange.getIn().setBody(fileContent);
exchange.getIn().setHeader("CamelFileName", fileNameforYourAdditionalFile)
String completeFilePath = systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath() + filepath
exchange.getIn().setHeader("destFilePath", completeFilePath);
}
})
.toD(sftpRoute()); // It is toD not to
}
private String sftpRoute() {
return String.format(SFTP_BASE_URL,systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
"${header.destFilePath}",
systemSettingsService.getSystemSettings().getSftpPassword())
}
}
我使用 DSL 配置和 spring。
我的路线是这样的:
@Component
public class UploadRoutesDefinition extends RouteBuilder {
@Override
public void configure() throws Exception {
from("seda:rest_upload")
.process(new Processor() {
@Override
public void process(Exchange exchange) {
...
String sftPathForAdditionalFile = ....
String AdditionalFileContent = ...
...
}
).to(String.format(SFTP_BASE_URL,systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath(),
systemSettingsService.getSystemSettings().getSftpPassword()))
它允许我从 seda:rest_upload
读取文件,然后将其移动到 sftp 文件夹。
我想再移动一个文件。我知道 process
方法中的路径和内容。
如何实现?
更新
我当前的代码;
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("CamelFilename", "ololo.txt");
exchange.getIn().setBody(exchange.getProperty(PUSH_ERROR_MESSAGE, String.class).getBytes());
exchange.getIn().setHeader("destFilePath", sftpErrorFileTextPath);
}
})
.to(String.format(SFTP_BASE_URL + "&fileExist=Append",
systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
"${header.destFilePath}",
systemSettingsService.getSystemSettings().getSftpPassword()))
.end();
这是一种方法,
@Override
public void configure() throws Exception {
from("seda:rest_upload")
.multicast()
.to("direct::sendMainFile")
.to("direct:sendAnotherFile") // You could also use seda:
.end();
from("direct:sendMainFile")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String filepath = <calculate filepath>;
String completeFilePath = systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath() + filepath
exchange.getIn().setHeader("destFilePath", completeFilePath);
exchange.getIn().setHeader("CamelFileName", fileNameforMainFile);
}
}.toD(sftpRoute()) // It is toD not to
from("direct:sendAnotherfile")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// Here you have the same body which was sent from rest_upload
// extract the info from exchange.getIn().getBody()
// Read the file and set it as exchange body
String fileContent = <Your logic to read file>
exchange.getIn().setBody(fileContent);
exchange.getIn().setHeader("CamelFileName", fileNameforYourAdditionalFile)
String completeFilePath = systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath() + filepath
exchange.getIn().setHeader("destFilePath", completeFilePath);
}
})
.toD(sftpRoute()); // It is toD not to
}
private String sftpRoute() {
return String.format(SFTP_BASE_URL,systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
"${header.destFilePath}",
systemSettingsService.getSystemSettings().getSftpPassword())
}
}