我使用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并将其复制到出站目录。但是,原始文件未被删除。有没有人知道为什么不呢?
答案 0 :(得分:2)
我知道很久以前就提出了这个问题,但也许答案对其他人有用。
中提供了未删除输入文件的原因
delete-source-files
属性只有在有效时才有效 入站消息具有文件有效负载或FileHeaders.ORIGINAL_FILE
标头值包含源文件实例或字符串 表示原始文件路径。
您的邮件不包含此特定标头。如果您使用其中一个standard file transformers(FileToStringTransformer
和FileToByteArrayTransformer
),则会自动设置。或者,您可以使用header enricher手动设置它。
Behind the scenes类似的事情发生在文件转换器中:
...
Message<?> transformedMessage = MessageBuilder.withPayload(result)
.copyHeaders(message.getHeaders())
.setHeaderIfAbsent(FileHeaders.ORIGINAL_FILE, file)
.setHeaderIfAbsent(FileHeaders.FILENAME, file.getName())
.build();
...
答案 1 :(得分:0)
来自文档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"/>
我不知道如何在入站通道适配器上执行此操作(我觉得这很有意义)