FileSystemAcceptOnceFilelistlistFilter不起作用 [英] FileSystemAcceptOnceFilelistFilter is not working

查看:241
本文介绍了FileSystemAcceptOnceFilelistlistFilter不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有一个Spring Boot应用程序,该应用程序将文件从源路径路由到目标路径.尝试运行多个指向同一源路径的应用程序实例.预期只有一个实例应该处理文件,并且一旦处理,它将从源中删除.同一文件不应由其他实例处理.

Have a spring boot application which routes file from source path to target path. Trying to run more than one instance of application pointing to same source path. Expecting only one instance should process a file and once processed it will be deleted from source. Same file should not be processed by other instance.

由于文件nio储物柜不起作用,建议根据共享的ConcurrentMetadataStore()-PropertiesPersistingMetadataStore使用FileSystemPersistentAcceptOnceFileListFilter.期望如此,实际上只有一个实例将拾取该文件进行处理.所有其他人都将跳过它,然后继续下一个文件.

Since file nio locker is not working, as suggested consider to use a FileSystemPersistentAcceptOnceFileListFilter based on the shared ConcurrentMetadataStore() - PropertiesPersistingMetadataStore. Expected that, this way really only one instance will pick up the file for processing. All others will skip it and move on to the next files.

但是两个实例选择的某些文件会选择/轮询同一文件并将其处理到目标路径.

But some files picked by both instance picks/polls same file and processing it to target path.

有什么建议吗?

 <bean id="metadatastore" class = "org.springframework.integration.metadata.PropertiesPersistingMetadataStore">
 <property name="basedirectory" value ="${java.io.tmpdir}/metadata"/>
 </bean>
 <bean id="inboundfilter" class = "org.springframework.integration.file.filters.CompositeFilelistFilter">
   <constructor-arg>
     <list>
       <bean class = "org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFilelistFilter">
          <constructor-arg name= "store" ref="metadatastore"/>
    <!-- Filename prefix constructor.  No prefix name in my case .so made it empty-->
          <constructor-arg value = ""/>
        </bean>
        <bean class = "org.springframework.integration.file.filters.RegexPatternFilelistFilter">
          <constructor-arg value="${regex}"/>
        </bean>
      </list>
  </constructor-arg>
 </bean>

推荐答案

首先还不清楚为什么在同一台计算机上会有同一应用程序的多个实例.对于相同的CPU和RAM,相同的应用程序绝对不会提高性能.

First of all it isn't clear why would one have several instances of the same application on the same machine. There is definitely no performance gain of the same application against the same CPU and RAM.

另一个担忧是,PropertiesPersistingMetadataStore对于分布式计算而言并不是那么好.您绝对需要考虑对共享数据库使用一些商店实现.

Another concern that PropertiesPersistingMetadataStore is not so good for distributed computation as is. You definitely need to consider to use some store implementation with the shared data base.

此外,您还可以通过以下方式使当前解决方案非常接近您想要的解决方案:

Also you can bring the current solution very close to what you would like to have with the:

/**
 * Determine whether the metadataStore should be flushed on each update (if {@link Flushable}).
 * @param flushOnUpdate true to flush.
 * @since 4.1.5
 */
public void setFlushOnUpdate(boolean flushOnUpdate) {

所提及的FileSystemPersistentAcceptOnceFilelistFilter

true.这样,每次写入存储后,PropertiesPersistingMetadataStore都将闪现到目标.properties文件中.

as true for the mentioned FileSystemPersistentAcceptOnceFilelistFilter. This way a PropertiesPersistingMetadataStore will be flashed to the target .properties file after each write to the store.

这篇关于FileSystemAcceptOnceFilelistlistFilter不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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