我有一个文件:inbound-channel-adapter,用于轮询目录中的文件,然后通过SFTP将其发送到服务器。上传后(工作正常),需要删除原始文件;如何上传原始文件后如何删除原始文件? 在文件:outbound-channel-adapter中,我可以设置一个属性来自动删除文件。
<file:inbound-channel-adapter
id="incomingFiles"
channel="myFiles"
directory="file:/tmp/kots">
<int:poller id="poller" fixed-delay="1000"/>
</file:inbound-channel-adapter>
<int:channel id="myFiles"/>
....
<sftp:outbound-channel-adapter
id="sftpOutboundAdapter"
channel="myFiles"
charset="UTF-8"
remote-directory="/tmp/testing"
session-factory="sftpSessionFactory"/>
答案 0 :(得分:4)
Transaction Synchronization适合您:
<file:inbound-channel-adapter
id="incomingFiles"
channel="myFiles"
directory="file:/tmp/kots">
<int:poller id="poller" fixed-delay="1000">
<int:transactional transaction-manager="transactionManager" synchronization-factory="syncFactory" />
</int:poller>
</file:inbound-channel-adapter>
<int:transaction-synchronization-factory id="syncFactory">
<int:after-commit expression="payload.delete()" channel="nullChannel"/>
</int:transaction-synchronization-factory>
开箱即用的transactionManager
可能是org.springframework.integration.transaction.PseudoTransactionManager
。