我必须轮询目录并将条目写入 RDBMS。 我连接了一个 redis 元数据存储来进行重复检查。我看到框架在写入 rdbms 条目之前就使用文件夹 [~ 140 个文件] 中所有文件的条目更新了 redis 存储。在应用程序终止时,rdbms 仅记录了 90 个文件。应用程序重新启动时,不再从文件夹中选取文件。
属性:msgs.per.poll=10,polling.interval=2000 如何确保在写入数据库后写入 Redis 条目,以便两者同步并且不会丢失任何文件。
<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 并与数据库同步。但这种事情有点耦合。
关于spring - 在 Spring 集成中防止重新启动时出现重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25756387/