基于内容的文件移动与骡 [英] Content based file moving with Mule

查看:131
本文介绍了基于内容的文件移动与骡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < flow name =HTTP input1> 
< / ftp:入站 - 终点>
< / file:outbound-endpoint>
< / flow>

我可以移动这些文件,但是我需要的是读取文件内容并根据如果我的文件内容有Vendor1,那么它应该把文件放在Vendor1下面。 FYI:Vendor1不是静态的。它可能Vendor1000。任何想法呢?

解决方案




  • 使用转换器从文件中提取所需的值(不是表达式,因为不支持您特定的文件格式),
  • 在路径属性中使用此属性


类似于:

 < flow name =HTTP input1> 
< ftp:inbound-endpoint user =username
password =secret
host =host
path =location
port = 21\" >
< / ftp:入站 - 终点>
< script:transformer name =stringReplaceWithParams>
< script:script engine =groovy>
< script:text>
//这里的有效载荷变量应该包含来自远程FTP文件
的byte [] // ... munch-munch用Groovy的字节[]来查找放在targetSubDir中的值
var targetSubDir = ...

message.setOuboundProperty('targetSubDir',targetSubDir)
//返回有效载荷不变,我们只是改变了一个消息属性
返回有效载荷
< / script:text>
< / script:script>
< / script:transformer>
outputPattern =#[header:originalFilename]/>
< / flow>


My mule config file contains the below flow:

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

I'm able to move the files but what I need is to read out the file content and based on that content place it in specific directory.

For example if my file content has "Vendor1" then it should place the file under Vendor1. FYI: Vendor1 is not static. It may Vendor1000. Any ideas on this?

解决方案

What you want to do is:

  • Extract the desired value from the file using a transformer (not an expression because none support your specific file format),
  • Use this property in the path attribute of the outbound endpoint.

Something like:

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

这篇关于基于内容的文件移动与骡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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