File 使用Mule移动基于内容的文件

File 使用Mule移动基于内容的文件,file,ftp,esb,mule,File,Ftp,Esb,Mule,我的mule配置文件包含以下流: <flow name="HTTP input1"> <ftp:inbound-endpoint user="username" password="secret" host="host" path="location" port="21"> <file:filename-wildcard-filter pattern="." /> </ftp:inbound-endpoint> <file

我的mule配置文件包含以下流:

<flow name="HTTP input1">
  <ftp:inbound-endpoint user="username" password="secret" host="host" path="location" port="21">
    <file:filename-wildcard-filter pattern="." />
  </ftp:inbound-endpoint>
  <file:outbound-endpoint path="E:/Mule/Inbound" outputPattern="#[header:originalFilename]" >
  </file:outbound-endpoint>
</flow>

我可以移动文件,但我需要的是读取文件内容,并根据该内容将其放在特定目录中


例如,如果我的文件内容有“Vendor1”,那么它应该将文件放在Vendor1下。仅供参考:Vendor1不是静态的。它可能卖1000英镑。对此有什么想法吗?

您想做的是:

  • 使用转换器(不是表达式,因为没有表达式支持特定的文件格式)从文件中提取所需的值
  • 在出站端点的路径属性中使用此属性
比如:

<flow name="HTTP input1">
  <ftp:inbound-endpoint user="username"
                        password="secret"
                        host="host"
                        path="location"
                        port="21">
    <file:filename-wildcard-filter pattern="." />
  </ftp:inbound-endpoint>
  <script:transformer name="stringReplaceWithParams">
    <script:script engine="groovy">
        <script:text>
          // here the payload variable should contain a byte[] from the remote FTP file
          // ... munch-munch the byte[] with Groovy to find the value to put in targetSubDir
          var targetSubDir = ...

          message.setOuboundProperty('targetSubDir', targetSubDir) 
          // return the payload unchanged, we just changed a message property
          return payload 
        </script:text>
    </script:script>
  </script:transformer>
  <file:outbound-endpoint path="E:/Mule/Inbound/#[header:targetSubDir]"
                          outputPattern="#[header:originalFilename]" />
</flow>

//此处,有效负载变量应包含来自远程FTP文件的字节[]
// ... 使用Groovy munch munch munch字节[],以查找要放入targetSubdr中的值
var targetSubDir=。。。
message.setOuboundProperty('targetSubDir',targetSubDir)
//返回未更改的有效负载,我们只是更改了一个消息属性
返回有效载荷

非常感谢您的支持。我也明白您的意思,但我有一个疑问,那就是如何使用mule表达式读取文件?或者,如果我编写自定义类,那么如何将返回值分配给属性键?对您来说,这可能是一个简单的问题,但我无法理解。非流式入站FTP端点将远程文件读取为字节[]。然后,您可以使用Mule表达式从这个字节[]获取一个值。例如,如果远程文件是XML格式,则可以使用XPath表达式提取所需的值。如果您指定此文件的格式,我将改进我的答案。好的,您如何在此CSV文件中找到所需的值?使用逗号分隔符。是否可以在此处使用?message.setProperty已弃用-,java.lang.Object)避免使用它!它与setOuboundProperty具有相同的签名,因此setOuboundProperty应该可以工作!