FileSystemAcceptOnceFilelistFilter is not working

Deadly 提交于 2019-12-13 03:46:15

问题


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.

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.

Any suggestion?

 <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>

回答1:


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.

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) {

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



来源:https://stackoverflow.com/questions/52047650/filesystemacceptoncefilelistfilter-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!