2014-09-12 22 views
1

首先,我今天剛剛開始關注Spring Integration,所以我幾乎沒有什麼經驗。我已經有一個使用彈簧集成的基本預定的ftp文件解析器設置:FTP/FTPS適配器自定義觸發器/輪詢器

<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;但是,我想添加額外的功能,在啓動預定(固定速率)ftp適配器之前,檢查系統是否準備就緒(以固定速率)。我堅持實施這個最好的方式。任何幫助或指導表示讚賞。

最好的問候,

賈裏德

回答

1

<poller>有像<advice-chain>的選項。

所以,你只需要編寫一些自定義Advice

public class CheckSystemInterceptor implements MethodInterceptor { 

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

} 

將其配置爲您的system checker一個<bean>並注入到該<advice-chain>

它將在每次投票中被調用。

+0

或者設置'auto-startup =「false」'並且只有在你準備好時才啓動適配器。或者,我通常建議在使用FTP執行「按需」類型應用程序時使用出站網關(LS,GET等)。 – 2014-09-12 17:16:20

+0

這工作完美,謝謝! – jared 2014-09-15 08:18:51