防止在 spring 集成中重新启动重复 [英] Prevent duplicates across restarts in spring integration

查看:21
本文介绍了防止在 spring 集成中重新启动重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须轮询一个目录并将条目写入 rdbms.我连接了一个 redis metadatstore 进行重复检查.我看到框架使用文件夹 [~ 140 个文件] 中所有文件的条目更新 redis 存储,远在 rdbms 条目被写入之前.在应用程序终止时,rdbms 仅记录了 90 个文件.在应用程序重新启动时,不再从文件夹中选取更多文件.

I have to poll a directory and write entries to rdbms. I wired up a redis metadatstore for duplicates check. I see that the framework updates the redis store with entries for all files in the folder [~ 140 files], much before the rdbms entries gets written. At the time of application termination, rdbms has logged only 90 files. On application restart no more files are picked from folder.

属性:msgs.per.poll=10,polling.interval=2000如何确保在写入 db 后对 redis 进行条目,以便两者同步并且我不会错过任何文件.

Properties: msgs.per.poll=10, polling.interval=2000 How can I ensure entries to redis are made after writing to db, so that both are in sync and I don't miss any files.

<code>
    <task:executor id="executor" pool-size="5" />
    <int-file:inbound-channel-adapter channel="filesIn" directory="${input.Dir}" scanner="dirScanner"    filter="compositeFileFilter" prevent-duplicates="true">
        <int:poller fixed-delay="${polling.interval}" max-messages-per-poll="${msgs.per.poll}" task-executor="executor">
        </int:poller>
    </int-file:inbound-channel-adapter>
    <int:channel id="filesIn" />

    <bean id="dirScanner" class="org.springframework.integration.file.RecursiveLeafOnlyDirectoryScanner" />

    <bean id="compositeFileFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
        <constructor-arg ref="persistentFilter" />
    </bean>

    <bean id="persistentFilter" class="org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter">
        <constructor-arg ref="metadataStore" />
    </bean>

    <bean name="metadataStore" class="org.springframework.integration.redis.metadata.RedisMetadataStore">
        <constructor-arg name="connectionFactory" ref="redisConnectionFactory"/>
    </bean>
    <bean id="redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:hostName="localhost" p:port="6379" />

    <int-jdbc:outbound-channel-adapter channel="filesIn" data-source="dataSource" query="insert into files values (:path,:name,:size,:crDT,:mdDT,:id)"
        sql-parameter-source-factory="spelSource">
    </int-jdbc:outbound-channel-adapter>

        ....
</code>

推荐答案

Artem 是对的,你不妨扩展 RedisMetadataStore 并在初始化时刷新数据库中没有的条目,这样你就可以使用 Redis 并与数据库同步.但这种夫妻的事情有点.

Artem is correct, you might as well extend the RedisMetadataStore and flush the entries that are not in your database on initialization time, this way you could use Redis and be in sync with the DB. But this kind of couples things a little.

这篇关于防止在 spring 集成中重新启动重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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