我正在使用 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 集成参考:

delete-source-files 属性仅在入站消息具有文件有效载荷或当 FileHeaders.ORIGINAL_FILE标头值包含代表原始文件路径的源文件实例或字符串。

您的邮件不包含此特定标头。如果您使用其中之一 标准文件转换器 (FileToStringTransformerFileToByteArrayTransformer)它将自动设置。或者,您可以使用手动设置 标题丰富器.

幕后花絮 文件转换器中正在发生类似的事情:

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

其他提示

从文档 http://static.springsource.org/spring - integration /参考/ html / files.html

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top