Spring Integration-file:inbound-channel-adapter-删除原始文件

Jan*_*ert 2 spring spring-integration

我有一个file:inbound-channel-adapter,它轮询目录中的文件,然后通过SFTP将其发送到服务器。上传完成后(可以正常使用),需要删除原始文件;上传原始文件后如何删除?在file: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"/>
Run Code Online (Sandbox Code Playgroud)

Art*_*lan 5

事务同步适合您:

<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>
Run Code Online (Sandbox Code Playgroud)

transactionManager可能org.springframework.integration.transaction.PseudoTransactionManager从开箱。