FTP/FTPS Adapters custom trigger/poller

限于喜欢 提交于 2019-12-11 10:25:33

问题


First, I have just started looking at Spring Integration today, so I have very little experience. I already have a basic scheduled ftp file parser setup using spring integration:

<int:channel id="ftpIn"  />

<int-ftp:inbound-channel-adapter 
    channel="ftpIn"
    session-factory="ftpClientFactory"
    filename-pattern="*.xml"
    local-directory="${TEMP_DIR}">

    <int:poller fixed-rate="${ftp.polling.rate}" />

</int-ftp:inbound-channel-adapter>

<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
    <property name="host" value="${ftp.host}" />
    <property name="port" value="${ftp.port}" />
    <property name="username" value="${ftp.username}" />
    <property name="password" value="${ftp.password}" />
</bean>

<int:service-activator
    input-channel="ftpIn"
    method="handle"
    ref="ftpInHandler" />

<bean id="ftpInHandler" class="thanks.for.looking.FtpInHandler" />

This works; however, I want to add additional functionality that checks (at a fixed-rate) if the system is ready before starting the scheduled (fixed-rate) ftp adapter. I am stuck on the best way to implement this. Any help or guidance is appreciated.

Best Regards,

Jared


回答1:


<poller> has an option like <advice-chain>.

So you just need to write some custom Advice:

public class CheckSystemInterceptor implements MethodInterceptor {

    Object invoke(MethodInvocation invocation) throws Throwable {
          return mySystem.isOK() ? invocation.proceed() : null;
    }

}

Configure it as a <bean> with your system checker and inject it into that <advice-chain>.

It will be invoked on each poll.



来源:https://stackoverflow.com/questions/25810528/ftp-ftps-adapters-custom-trigger-poller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!