与RedisLockRegistry的Spring集成示例 [英] Spring Integration with RedisLockRegistry example

查看:154
本文介绍了与RedisLockRegistry的Spring集成示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在实现一个流程,其中<int-sftp:inbound-streaming-channel-adapter/>轮询目录中的文件,并在找到时将其传递给服务激活器.

We are implementing a flow where a <int-sftp:inbound-streaming-channel-adapter/> polls a directory for a file and when found it passes the stream to a service activator.

问题是我们将有多个应用程序实例在运行,我们希望锁定该过程,以便只有一个实例可以提取该文件.

The issue is we will have multiple instances of the app running and we would like to lock the process so that only one instance can pick up the file.

查看文档,Redis Lock Registry似乎是解决方案,是否有在xml中使用的示例?

Looking at the documentation, Redis Lock Registry looks to be the solution, is there an example of this being used in xml?

我所能找到的只是对它的一些引用以及它的源代码.

All I can find is a few references to it and the source code for it.

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

添加的信息: 我已经添加了RedisMetaDataStore和SftpSimplePatternFileListFilter.它确实可以工作,但确实有一个奇怪之处,当轮询器激活sftpInboundAdapter时,它将为元数据存储中的每个文件添加一个条目.假设有10个文件,则数据存储区中将有10个条目,但是它不会在"1 go"中处理所有10个文件,从适配器的每次轮询仅处理1个文件,这很好,但是在多实例中在环境中,如果拾取文件的服务器在处理5个文件后发生故障,那么除非触摸"文件,否则另一台服务器似乎不会拾取其余5个文件.

Added info: Ive added the RedisMetaDataStore and SftpSimplePatternFileListFilter. It does work but it does have one oddity, when sftpInboundAdapter is activated by the poller it adds an entry for each file in the metadatastore. Say there are 10 files, there would be 10 entries in the datastore, but it does not process all 10 files in "1 go", only 1 file is processed per poll from the adapter, which would be fine, but in a multi instance environment if the server which picked up the files went down after processing 5 files, another server doesn't seem to pick up the remaining 5 files unless the files are "touched".

在每次轮询中拾取1个文件的行为是正确的还是应该在一次轮询期间处理所有有效文件的行为.

Is the behaviour of picking up 1 file per poll correct or should it process all valid files during one poll.

下面是我的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>

推荐答案

否;您需要使用SftpPersistentAcceptOnceFileListFilter(此处的文档)和Redis(或其他一些)元数据存储区,而不是锁定注册表.

No; you need to use a SftpPersistentAcceptOnceFileListFilter (docs here) with a Redis (or some other) metadata store, not a lock registry.

编辑

关于您在下面的评论.

是的,这是一个已知问题;在正是由于这个原因,我们在下一个发行版中添加了max-fetch-size-因此,每个实例都可以检索某些文件,而不是第一个实例将它们全部抓取.

Yes, it's a known issue; in the next release we've added a max-fetch-size for exactly this reason - so the instances can each retrieve some of the files rather than the first instance grabbing them all.

(入站适配器的工作方式是,首先将找到的尚未存储的文件复制到本地磁盘,然后一次将其发出).

(The inbound adapter works by first copying files found, that are not already in the store, to the local disk, and then emits them one at a time).

5.0仅作为里程碑提供,在撰写本文时为M2,但当前版本为里程碑回购可以在这里找到;它不会再发布几个月了.

5.0 only available as a milestone right now M2 at the time of writing, but the current version and milestone repo can be found here; it won't be released for a few more months.

另一种替代方法是使用出站网关-一个用于LS文件,另一个用于GET单个文件;但是,您的应用程序必须使用元数据存储本身来确定可以提取哪些文件.

Another alternative would be to use outbound gateways - one to LS the files and one to GET individual files; your app would have to use the metadata store itself, though, to determine which file(s) can be fetched.

这篇关于与RedisLockRegistry的Spring集成示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆