【问题标题】:Spring Integration move file to another folder then send to sftp serverSpring Integration 将文件移动到另一个文件夹,然后发送到 sftp 服务器
【发布时间】:2019-02-21 07:31:17
【问题描述】:

我想创建一个应用程序,我将在其中收听 用于文本文件的名为“输入”的文件夹,然后将文本文件移动到“输出” 然后将其发送到 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 通道不起作用。我尝试评论句柄方法和 sftp 通道将工作。 我只想先将文件放到输出目录,然后再发送到 sftp。 我在 Spring Integration DSL 中看到了一个“路由”功能,但不确定这是否适合使用。

提前谢谢你。

【问题讨论】:

    标签: java spring spring-integration


    【解决方案1】:

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

    另一个问题是FileWritingMessageHandler网关模式下能够产生回复,所以它允许配置setOutputChannel()

    如果不是关于Files.outboundGateway(),我想我们可以考虑拒绝这样的配置。

    请在参考手册中查看更多信息:https://docs.spring.io/spring-integration/docs/current/reference/html/#file-writing-output-gateway

    【讨论】:

      【解决方案2】:

      Spring 中的文件处理程序: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"/>
      

      【讨论】:

        猜你喜欢
        • 2016-04-11
        • 2013-10-01
        • 2021-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多