问题描述
我想创建一个应用程序,在该应用程序中,我将收听名为文本文件的“ input”文件夹,然后将文本文件移至“ output”,然后将其发送到sftp服务器。 这是我在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();
}
现在发生的是,当我将文本文件放在“输入”目录中时,该文件随后成功移至“输出”目录,但发送至sftp通道不起作用。 我尝试评论handle方法,并且sftp通道将起作用。 我只想先将文件发送到输出目录,然后再将其发送到sftp。 我在Spring Integration DSL中看到了“路由”功能,但不确定是否合适。
先感谢您。
1楼
对于这样的流程,您应该使用Files.outboundGateway()
而不是单向的Files.outboundAdapter()
。
最后一个问题是它不会产生答复以发送到下一个频道。
FileWritingMessageHandler
处于网关模式时能够产生答复的另一个问题是,它允许配置setOutputChannel()
。
我认为,如果与Files.outboundGateway()
我们可以考虑拒绝此类配置。
请在参考手册中查看更多信息: :
2楼
春季文件处理程序:D
不确定我的答案
<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"/>