2017-02-17 42 views
1

我們正在實現一個流程,其中<int-sftp:inbound-streaming-channel-adapter/>爲文件輪詢一個目錄,並在發現它將該流傳遞給服務激活器時。Spring與RedisLockRegistry示例的集成

問題是我們將運行該應用程序的多個實例,並且我們想要鎖定該進程,以便只有一個實例可以提取該文件。

看看文檔,Redis鎖註冊表看起來是解決方案,是否有這樣的例子在XML中使用?

所有我能找到的是它的一些參考和它的源代碼。

http://docs.spring.io/spring-integration/reference/html/redis.html點24.1

新增信息: 伊夫加入RedisMetaDataStore和SftpSimplePatternFileListFilter。它確實有效,但它確實有一個奇怪之處,當它由輪詢器激活sftpInboundAdapter時,它會爲元數據存儲中的每個文件添加一個條目。假設有10個文件,數據存儲中會有10個條目,但它不會處理「1次」中的所有10個文件,每個輪詢只能從適配器處理1個文件,這很好,但在多實例環境如果處理5個文件後拾取文件的服務器出現故障,另一個服務器似乎無法拾取剩餘的5個文件,除非文件被「觸摸」。

是否每個輪詢都選取一個文件的行爲是正確的,還是應該在一次輪詢期間處理所有有效的文件?

下面是我的XML

<int:channel id="sftpInbound"/> <!-- To Java --> 
<int:channel id="sftpOutbound"/> 
<int:channel id="sftpStreamTransformer"/> 

<int-sftp:inbound-streaming-channel-adapter id="sftpInboundAdapter" 
     channel="sftpInbound" 
     session-factory="sftpSessionFactory" 
     filter="compositeFilter" 
     remote-file-separator="/" 
     remote-directory="${sftp.directory}"> 
    <int:poller cron="${sftp.cron}"/> 
</int-sftp:inbound-streaming-channel-adapter> 

<int:stream-transformer input-channel="sftpStreamTransformer" output-channel="sftpOutbound"/> 

<bean id="compositeFilter" 
    class="org.springframework.integration.file.filters.CompositeFileListFilter"> 
    <constructor-arg> 
     <list> 
      <bean 
       class="org.springframework.integration.sftp.filters.SftpSimplePatternFileListFilter"> 
       <constructor-arg value="Receipt*.txt" /> 
      </bean> 
      <bean id="SftpPersistentAcceptOnceFileListFilter" class="org.springframework.integration.sftp.filters.SftpPersistentAcceptOnceFileListFilter"> 
       <constructor-arg ref="metadataStore" />     
       <constructor-arg value="ReceiptLock_" />      
      </bean> 
     </list> 
    </constructor-arg> 
</bean> 

<bean id="redisConnectionFactory" 
    class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> 
    <property name="port" value="${redis.port}" /> 
    <property name="password" value="${redis.password}" /> 
    <property name="hostName" value="${redis.host}" /> 
</bean> 

回答

0

否;您需要將SftpPersistentAcceptOnceFileListFilterdocs here)與Redis(或其他)元數據存儲一起使用,而不是鎖註冊表。

編輯

關於下面的評論。

是的,這是一個已知的問題;在next release中,我們增加了一個max-fetch-size,因爲這個原因 - 所以這些實例可以分別檢索一些文件,而不是第一個實例抓取它們。

(入站適配器首先將找到的文件複製到本地磁盤,然後一次發出一個)。

5.0僅作爲目前的里程碑提供M2 at the time of writing, but the current version and milestone repo can be found here;它將不會再發布幾個月。

另一種選擇是使用出站網關 - 一個LS文件和一個GET單個文件;但是,您的應用程序必須使用元數據存儲本身來確定可以提取哪些文件。

+0

謝謝Gary,Ive按照您的建議實施,我認爲它幾乎在那裏,我添加了額外的信息解釋問題的原始問題。 – sdiaz1000

+0

請參閱編輯我的答案以獲取更多信息。 –

+0

我剛剛解決了這個問題,我爲輪詢器添加了max-messages-per-poll屬性並將其設置爲10,工作正常。謝謝。 – sdiaz1000