代码之家  ›  专栏  ›  技术社区  ›  Pathfinder

Mule文件入站-未触发空文件

  •  0
  • Pathfinder  · 技术社区  · 7 年前

    我有一个场景,需要从特定文件夹中读取文件。所以我有一个文件,如下所示,它读取所有 非空文件 . 但空文件不会被读取,并且与原样位于同一位置。

        <file:inbound-endpoint path="${file.path}" responseTimeout="10000" doc:name="File" moveToDirectory="${audit.location}">
           <file:filename-regex-filter pattern="file.employee(.*).xml,file.client(.*).xml" 
              caseSensitive="true"/>
        </file:inbound-endpoint>
    

    空的 文件夹。

    5 回复  |  直到 7 年前
        1
  •  3
  •   Pierre B.    7 年前

    根据 Mule File Connector documentation :

    作为入站端点的文件连接器不处理空(0字节)文件。

    但是,您仍然可以编写自己的连接器来实现这一点,或者使用解决方法,例如用单个字符(例如空格)填充“空”文件,使其非空

        2
  •  1
  •   SreenivasB    7 年前

    如果您想读取大小为0 KB的文件,那么使用file Connector无法实现这一点,但我们可以使用 多路请求器 在流程中。我将很快分享示例片段。如果你需要帮助,请告诉我。

    当做 Sreenivas B

        3
  •  0
  •   Mowmita    7 年前

    Mule File connector不会将空(0字节)文件作为入站端点进行处理

        4
  •  0
  •   Prudhvi Veerlapati    7 年前

    据我所知,文件入站连接器不会处理(0 KB)大小的文件。

        5
  •  0
  •   Jesus R Marval P    5 年前

    if (file.length() == 0)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Found empty file '" + file.getName() + "'. Skipping file.");
        }
        continue;
    }
    

    这会阻止它处理空文件

    但您可以创建自己的CustomFileMessageReceiver。java,创建包:

    package com.mycompany.mule.transport.file;
    

    以及扩展AbstractPollingMessageReceiver的类

    public class CustomFileMessageReceiver extends AbstractPollingMessageReceiver
    

    呼叫文件连接器。move(file,workFile)是一种受原始软件包保护的方法,请注意,您不能使用workdir。

    在同一个包中创建org的副本。骡子运输文件ReceiverFileInputStream。Java语言

    配置连接器:

        <file:connector name="FILE" readFromDirectory="${incoming.directory}" autoDelete="true" streaming="false" recursive="true" validateConnections="true" doc:name="File" writeToDirectory="${processed.directory}">
                <service-overrides messageReceiver="com.mycompany.mule.transport.file.CustomFileMessageReceiver"  />
        </file:connector>
    

    或者您可以实现自己的文件连接器,如上述答案所述。