Spring集成FTP:删除所有源文件夹文件时自动停止文件入站通道适配器

时间:2014-11-19 13:23:33

标签: spring-integration

是否有任何配置设置/表达式根据条件停止通道适配器(即,当源文件夹为空时停止通道适配器)?

我可以通过编程方式执行此操作,但这种方法在我的案例中不起作用。

配置:

 <file:inbound-channel-adapter prevent-duplicates="false" auto-startup="false" auto-create-directory="true" directory="${local.tmp.path}" id="fileInbound" channel="outputChannel" filename-pattern="*.xml">
        <int:poller fixed-rate="${local.transfer.interval}" max-messages-per-poll="100" />
   </file:inbound-channel-adapter>

<sftp:outbound-channel-adapter id="sftpFileOutboundAdapter" auto-create-directory="true" session-factory="sftpSessionFactory" channel="outputChannel" charset="UTF-8" remote-directory="${ftp.path}">
    <sftp:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <property name="onSuccessExpression" value="payload.delete()" />
            <property name="trapException" value="true" />
        </bean>
    </sftp:request-handler-advice-chain>
</sftp:outbound-channel-adapter>

代码:

fileInbound = context.getBean("fileInbound", SourcePollingChannelAdapter.class);
if (fileInbound.isRunning() && isSourcefolderEmpty()) {
     fileInbound.stop();
 }

1 个答案:

答案 0 :(得分:0)

这样的事情应该有效。

  1. onSuccessExpression使用payload并添加successChannel

  2. successChannel设为<publish-subsribe-channel/>

  3. 第一个订阅者(order="1")是<service-activator/> payload.delete()

  4. 第二个订阅者(order="2")是<chain/>,以<filter/>开头,检查目录是否为空......

  5.  <chain ...>
         <filter expression="new java.io.File('/tmp/foo').list().length == 0" />
         <transformer expression="@fileInbound.stop()"/>
         <control-bus/>
     </chain>