【问题标题】:Spring Integration, delete file in outbound channel adapterSpring Integration,删除出站通道适配器中的文件
【发布时间】:2012-09-24 07:14:28
【问题描述】:

我正在使用 Spring Integration 轮询文件的目录,在服务类中处理此文件,将此文件写入输出目录,然后删除原始文件。

我有以下 XML 配置:

  <int-file:inbound-channel-adapter id="filesInChannel"
                                    directory="file:${java.io.tmpdir}/input" 
                                    auto-create-directory="true"  >
      <int:poller id="poller" fixed-delay="1000" />
  </int-file:inbound-channel-adapter>

  <int:service-activator id="servicActivator"
                         input-channel="filesInChannel"
                         output-channel="filesOut"
                         ref="my_file_processing_service">
  </int:service-activator>

  <int-file:outbound-channel-adapter  id="filesOut" auto-create-directory="true" delete-source-files="true" directory="file:${java.io.tmpdir}/output"/>

这会轮询文件,将其传递给我的 processing_service 并将其复制到出站目录。但是原始文件不会被删除。有没有人知道为什么不呢?

【问题讨论】:

    标签: spring integration delete-file channel outbound


    【解决方案1】:

    我知道这个问题是很久以前提出的,但也许答案对其他人有用。

    Spring Integration Reference中提供了输入文件不被删除的原因:

    delete-source-files 属性只有在 入站消息具有文件有效负载,或者如果 FileHeaders.ORIGINAL_FILE 标头值包含源文件实例或字符串 表示原始文件路径。

    您的邮件不包含此特定标题。如果您使用standard file transformersFileToStringTransformerFileToByteArrayTransformer)之一,它将自动设置。或者,您可以使用 header enricher 手动设置它。

    Behind the scenes 文件转换器中正在发生类似的事情:

    ...
    Message<?> transformedMessage = MessageBuilder.withPayload(result)
            .copyHeaders(message.getHeaders())
            .setHeaderIfAbsent(FileHeaders.ORIGINAL_FILE, file)
            .setHeaderIfAbsent(FileHeaders.FILENAME, file.getName())
            .build();
    ...
    

    【讨论】:

      【解决方案2】:

      来自文档http://static.springsource.org/spring-integration/reference/html/files.html

      <int-file:outbound-gateway id="mover" request-channel="moveInput"
      reply-channel="output"
      directory="${output.directory}"
      mode="REPLACE" delete-source-files="true"/>
      

      我不知道如何在入站通道适配器上执行此操作(我认为这是有道理的)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-12
        • 2016-07-19
        • 2014-06-29
        • 1970-01-01
        • 1970-01-01
        • 2016-11-17
        • 2017-10-08
        • 1970-01-01
        相关资源
        最近更新 更多