当前位置: 代码迷 >> java >> Spring Integration将文件移动到另一个文件夹,然后发送到sftp服务器
  详细解决方案

Spring Integration将文件移动到另一个文件夹,然后发送到sftp服务器

热度:60   发布时间:2023-07-17 20:07:01.0

我想创建一个应用程序,在该应用程序中,我将收听名为文本文件的“ 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中看到了“路由”功能,但不确定是否合适。

先感谢您。

对于这样的流程,您应该使用Files.outboundGateway()而不是单向的Files.outboundAdapter() 最后一个问题是它不会产生答复以发送到下一个频道。

FileWritingMessageHandler处于网关模式时能够产生答复的另一个问题是,它允许配置setOutputChannel()

我认为,如果与Files.outboundGateway()我们可以考虑拒绝此类配置。

请在参考手册中查看更多信息: :

春季文件处理程序: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"/>
  相关解决方案