我们正在实现一个流程,其中<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