2017-02-17 94 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