使用 Spring 集成 ftp 入站适配器将处理过的文件移动到另一个目录

Moving processed files to another directory using Spring integration ftp inbound adapter

我正在尝试使用 ftp 入站适配器轮询本地目录以获取文件以进行进一步处理。我想将文件移动到另一个本地目录并将其从原始目录中删除。没有办法实现它。这是我目前所拥有的:

<int-ftp:inbound-channel-adapter id="ftpInbound"
    channel="ftpChannel" session-factory="ftpClientFactory"
    filename-pattern="*.xml" auto-create-local-directory="false"
    delete-remote-files="false" remote-directory="/" local-directory="//C://FBS//testmq">
    <int:poller fixed-rate="20000" />
</int-ftp:inbound-channel-adapter>

<int:channel id="ftpChannel">
    <int:queue />
</int:channel>

使用伪事务管理器进行事务同步;见file example in the documentation。这是文档该部分的配置:

<int-file:inbound-channel-adapter id="inputDirPoller"
    channel="someChannel"
    directory="/foo/bar"
    filter="filter"
    comparator="testComparator">
    <int:poller fixed-rate="5000">
        <int:transactional transaction-manager="transactionManager" synchronization-factory="syncFactory" />
    </int:poller>
</int-file:inbound-channel-adapter>

<int:transaction-synchronization-factory id="syncFactory">
    <int:after-commit expression="payload.renameTo(new java.io.File('/success/' + payload.name))" 
           channel="committedChannel" />
    <int:after-rollback expression="payload.renameTo(new java.io.File('/failed/' + payload.name))"
           channel="rolledBackChannel" />
</int:transaction-synchronization-factory>

继续阅读下一节...

Referring to the above section, you may be thinking it would be useful to take these 'success' or 'failure' actions when a flow completes, even if there is no 'real' transactional resources (such as JDBC) downstream of the poller. For example, consider a followed by an ftp:outbout-channel-adapter/. Neither of these components is transactional but we might want to move the input file to different directories, based on the success or failure of the ftp transfer.

To provide this functionality, the framework provides a PseudoTransactionManager, enabling the above configuration even when there is no real transactional resource involved. If the flow completes normally, the beforeCommit and afterCommit synchronizations will be called, on failure the afterRollback will be called. Of course, because it is not a real transaction there will be no actual commit or rollback. The pseudo transaction is simply a vehicle used to enable the synchronization features.