我在使用 DSL 的 SFTP 出站网关时遇到问题。 我想使用出站网关发送文件,然后继续我的流程。 问题是我有一个异常告诉我:
IllegalArgumentException: 'remoteDirectoryExpression' is required
我看到我可以使用 RemoteFileTemplate,在其中我可以设置 sftp session 工厂以及远程目录信息,但是我不需要的目录是由在启动之前放入 header 中的代码在我的流程中定义的。批。
@Bean
public IntegrationFlow orderServiceFlow() {
return f -> f
.handleWithAdapter(h -> h.httpGateway("myUrl")
.httpMethod(HttpMethod.GET)
.expectedResponseType(List.class)
)
.split()
.channel(batchLaunchChannel());
}
@Bean
public DirectChannel batchLaunchChannel() {
return MessageChannels.direct("batchLaunchChannel").get();
}
@Bean
public IntegrationFlow batchLaunchFlow() {
return IntegrationFlows.from(batchLaunchChannel())
.enrichHeaders(h -> h
.headerExpression("oiCode", "payload")
)
.transform((GenericTransformer<String, JobLaunchRequest>) message -> {
JobParameters jobParameters = new JobParametersBuilder()
.addDate("exec_date", new Date())
.addString("oiCode", message)
.toJobParameters();
return new JobLaunchRequest(orderServiceJob, jobParameters);
})
.handle(new JobLaunchingMessageHandler(jobLauncher))
.enrichHeaders(h -> h
.headerExpression("jobExecution", "payload")
)
.handle((p, h) -> {
//Logic to retreive file...
return new File("");
})
.handle(Sftp.outboundGateway(sftpSessionFactory,
AbstractRemoteFileOutboundGateway.Command.PUT,
"payload")
)
.get();
}
我不知道如何告诉我的出站网关哪个目录将取决于我的 header 中的内容。
最佳答案
Sftp.outboundGateway()
具有带有 RemoteFileTemplate
的重载版本。因此,您需要实例化 SftpRemoteFileTemplate
bean 并配置它:
/**
* Set the remote directory expression used to determine the remote directory to which
* files will be sent.
* @param remoteDirectoryExpression the remote directory expression.
*/
public void setRemoteDirectoryExpression(Expression remoteDirectoryExpression) {
这个可以像FunctionExpression
:
setRemoteDirectoryExpression(m -> m.getHeaders().get("remoteDireHeader"))
关于spring-integration - 使用 DSL 的 sftp 出站网关的远程目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48341438/