我們正在實現一個流程,其中<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>
謝謝Gary,Ive按照您的建議實施,我認爲它幾乎在那裏,我添加了額外的信息解釋問題的原始問題。 – sdiaz1000
請參閱編輯我的答案以獲取更多信息。 –
我剛剛解決了這個問題,我爲輪詢器添加了max-messages-per-poll屬性並將其設置爲10,工作正常。謝謝。 – sdiaz1000