[英]Spring Integration move file to another folder then send to sftp server
I would like create an app where in i will listen to a folder named "input" for a text file then move the text file to "output" then send it to sftp server. 我想创建一个应用程序,在该应用程序中,我将收听名为文本文件的“ input”文件夹,然后将文本文件移至“ output”,然后将其发送到sftp服务器。 here is my code in Spring Integration.
这是我在Spring Integration中的代码。
@Bean
public IntegrationFlow textFileIntegration(@Value("${input.dir}") File in,
@Value("${output.dir}") File out,
MessageChannel sftpChannel) {
return IntegrationFlows
.from(Files.inboundAdapter(in)
.autoCreateDirectory(true)
.patternFilter("*.txt"),
sourcePollingChannelAdapterSpec ->
sourcePollingChannelAdapterSpec.poller(pollerFactory -> pollerFactory.fixedRate(1000)))
//.transform(File.class, file -> service.process(file)) commented on purpose
.handle(Files.outboundAdapter(out))
.channel(sftpChannel)
.get();
}
Now what's happening is when i put the text file in "input" directory, the file then successfully move to "output" directory but the sending to sftp channel don't work. 现在发生的是,当我将文本文件放在“输入”目录中时,该文件随后成功移至“输出”目录,但发送至sftp通道不起作用。 I tried commenting the handle method and sftp channel will work.
我尝试评论handle方法,并且sftp通道将起作用。 I just want to put first the file to output directory before sending it to sftp.
我只想先将文件发送到输出目录,然后再将其发送到sftp。 I see a "route" function in Spring Integration DSL but not sure if that's the right one to use.
我在Spring Integration DSL中看到了“路由”功能,但不确定是否合适。
Thank you in advance. 先感谢您。
For such a flow you should use a Files.outboundGateway()
instead of one-way Files.outboundAdapter()
. 对于这样的流程,您应该使用
Files.outboundGateway()
而不是单向的Files.outboundAdapter()
。 The problem with the last one that it just doesn't produce a reply to be sent to the next channel. 最后一个问题是它不会产生答复以发送到下一个频道。
Another problem that FileWritingMessageHandler
is able to produce a reply when it is in the gateway mode, so it allows to configure a setOutputChannel()
. FileWritingMessageHandler
处于网关模式时能够产生答复的另一个问题是,它允许配置setOutputChannel()
。
I think we may consider to reject such a configuration if it is not about Files.outboundGateway()
. 我认为,如果与
Files.outboundGateway()
我们可以考虑拒绝此类配置。
Please, see more info in the Reference Manual: https://docs.spring.io/spring-integration/docs/current/reference/html/#file-writing-output-gateway 请在参考手册中查看更多信息: https : //docs.spring.io/spring-integration/docs/current/reference/html/#file-writing-output-gateway
File HANDLER in Spring :D 春季文件处理程序:D
Not sure about my answer 不确定我的答案
<file:inbound-channel-adapter id="filesIn" directory="/inbound">
<int:poller fixed-delay="1000"/>
</file:inbound-channel-adapter>
<file:outbound-channel-adapter id="filesOut" directory="/outbound"/>
<int:service-activator input-channel="filesIn"
output-channel="filesOut"
ref="handler"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.