我们正在实现一个流程,其中<int-sftp:inbound-streaming-channel-adapter/>
轮询文件的目录,并在找到时将流传递给服务激活器。
问题是我们将运行应用程序的多个实例,我们希望锁定进程,以便只有一个实例可以获取文件。
查看文档,Redis Lock Registry 看起来是解决方案,有没有在 xml 中使用的示例?
我所能找到的只是一些对它的引用和它的源代码。
http://docs.spring.io/spring-integration/reference/html/redis.html点 24.1
添加信息: 我添加了 RedisMetaDataStore 和 SftpSimplePatternFileListFilter。它确实有效,但确实有一个奇怪之处,当轮询器激活 sftpInboundAdapter 时,它会为元数据存储中的每个文件添加一个条目。假设有 10 个文件,数据存储中将有 10 个条目,但它不会处理“1 go”中的所有 10 个文件,适配器每次轮询只处理 1 个文件,这很好,但在多实例中环境 如果拾取文件的服务器在处理 5 个文件后停机,则除非文件被“触摸”,否则另一台服务器似乎不会拾取剩余的 5 个文件。
每次轮询获取 1 个文件的行为是否正确,或者是否应该在一次轮询期间处理所有有效文件。
下面是我的 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>