【问题标题】:Reading file using Spring Integration and want to use filter for ordering and file pick up使用 Spring Integration 读取文件并希望使用过滤器进行排序和文件提取
【发布时间】:2020-09-09 17:15:54
【问题描述】:

我正在尝试实现一个场景,其中运行在 Kubernetes 环境中的多个 pod 上的 spring 集成应用程序试图从一个目录中读取文件。

  1. 在阅读时,我正在对文件应用锁定,但应用锁定后,我无法处理文件并将文件重命名或移动到另一个文件夹。
    file:nio-locker/强>

  2. 一旦我释放锁,我就可以读取文件并处理文件。

FileLocker locker = new NioFileLocker();
locker.unlock(file);
  1. 为避免冲突,释放锁后,两个实例读取同一个数据文件,我想创建一个临时文件,文件名和前缀为_processing。

  2. 因此,任何从目录中读取文件进行处理的文件适配器都不应读取具有另一个文件名和_处理后缀的文件的文件。

总结:

一个。文件适配器(将选择未锁定且不包含具有 _processing 前缀的另一个文件的文件)。
湾。读取文件取锁。
C。使用文件名和 _processing 前缀创建临时文件。
d 解锁文件并使用转换器和批处理作业对其进行处理。
e.另一个从目录中读取文件的 pod 将检查未锁定且没有临时文件的文件。

 <file:inbound-channel-adapter
             channel="input"
             directory="C:/Users/*****/TestFileIntegration/inputWithData"
             auto-startup="true"
             prevent-duplicates="true"
             queue-size="10"
             use-watch-service="true">
        <int:poller id="poller" fixed-delay="1" />
        <file:nio-locker/>
     </file:inbound-channel-adapter>

我需要两点帮助
1.以某种方式读取文件,代码首先选择最旧的文件,最后选择最新的文件。
2.过滤和读取没有名为 fileName_Processing 的临时文件且未锁定的文件。

【问题讨论】:

    标签: spring-integration spring-integration-sftp


    【解决方案1】:

    考虑不使用&lt;file:nio-locker/&gt;,而是配置FileSystemPersistentAcceptOnceFileListFilter 和共享MetadataStore。因此,您的应用程序的每个实例都将在查询文件之前先咨询该存储。如果有一个文件的条目,它将被当前实例跳过:https://docs.spring.io/spring-integration/docs/5.3.2.RELEASE/reference/html/file.html#file-reading

    对于您正在寻找的订单, &lt;file:inbound-channel-adapter&gt; 上有一个 comparator 选项:

    <xsd:attribute name="comparator" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation><![CDATA[
    Specify a Comparator to be used when ordering Files. If none is provided, the
    order will be determined by the java.io.File implementation of Comparable.  MUTUALLY EXCLUSIVE with queue-size.
                    ]]></xsd:documentation>
                </xsd:annotation>
            </xsd:attribute>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 1970-01-01
      • 2016-12-15
      • 2012-05-24
      相关资源
      最近更新 更多