Question

I am new to Mule. I have to do the following task.

A file is at some location. I need to move that file to some other location. The criteria to select the location is based on file name.

Suppose, the file name is 'abc_loc1'. Then this file is to be moved into folder Location1. If the file name is 'abc_loc2', it should be moved into Location2.

Était-ce utile?

La solution

You can use the Mule file transport with inbound and outbound endpoints to move files, and either set a dynamic path attribute for the outbound, or use choice routing based on the original filename. You will have the original file name available as #[message.inboundProperties.originalFilename].

UPDATE (example flow):

<file:connector name="File"/>
<flow name="exampleFlow">
    <file:inbound-endpoint connector-ref="File" path="/tmp/1" responseTimeout="10000" />
    <set-variable variableName="myPath" value="#[message.inboundProperties['originalFilename'].substring(message.inboundProperties['originalFilename'].indexOf('_')+1)]" />
    <file:outbound-endpoint path="/tmp/#[flowVars['myPath']]" responseTimeout="10000" connector-ref="File" outputPattern="error#[message.inboundProperties['originalFilename']]"/>
</flow>

UPDATE 2:

to use choice routing replace the above file-outbound with something like this:

<choice>
    <when expression="#[flowVars['myPath'] == '1']">
        <file:outbound-endpoint path="/tmp/1" responseTimeout="10000" connector-ref="File" outputPattern="error#[message.inboundProperties['originalFilename']]"/>
    </when>
    <when expression="#[flowVars['myPath'] == '2']">
        <file:outbound-endpoint path="/tmp/2" responseTimeout="10000" connector-ref="File" outputPattern="error#[message.inboundProperties['originalFilename']]"/>
    </when>
</choice>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top