Question

I have a mule flow as under

<flow name="flow1" doc:name="f1">
    <file:inbound-endpoint path="C:\input" responseTimeout="10000"
        doc:name="File" />
</flow>

<flow name="flow2" doc:name="f2">
    <http:inbound-endpoint address="http://localhost:8080"
        doc:name="HTTP" exchange-pattern="request-response" />
    <flow-ref name="flow1" doc:name="Flow Reference" />
    <file:outbound-endpoint path="C:\outputfile"
        responseTimeout="10000" doc:name="File" />
</flow>

I am trying to move/upload multiple files from source to destination (can be anything e.g. FTP or File outbound etc..) by using the flow.

The reason for doing in this way is that I want to invoke the job from CLI(Command Line Interface) using CURL.

But it is not working....

Edited

I need to pick up some files(multiple files) from a particular folder located in my hard drive. And then move those to some outbound process which can be FTP site or some other hard drive location. But this flow needs to be invoked from CLI.

Edited (Based on David's answer)

I now have the flow as under

<flow name="filePickupFlow" doc:name="flow1" initialState="stopped">
     <file:inbound-endpoint path="C:\Input" responseTimeout="10000" doc:name="File"/>
            
      <logger message="#[message.payloadAs(java.lang.String)]" level="ERROR" />
</flow>

<flow name="flow2" doc:name="flow2">
  <http:inbound-endpoint address="http://localhost:8080/file-pickup/start" doc:name="HTTP" exchange-pattern="request-response"/>
  
  <expression-component>
        app.registry.filePickupFlow.start();
    </expression-component>
 
 <file:outbound-endpoint path="C:\outputfile" responseTimeout="10000" doc:name="File"/>

</flow>

I am getting couple of problems

a) I am getting an error that - Attribute initialState is not defined as a valid property of flow

enter image description here

However, if I remove that attribute, the flow continues without waiting for "http://localhost:8080/file-pickup/start" to fire up.

b) The files are not moved to the destination folder

So how can I do so?

Était-ce utile?

La solution

You can't reference a flow that has an inbound endpoint in it because such a flow is already active and consuming events from its inbound endpoint so you can't invoke it on demand.

The following, tested on Mule 3.3.1, shows how to start a "file pickup flow" on demand from an HTTP request.

<flow name="filePickupFlow" initialState="stopped">
    <file:inbound-endpoint path="///tmp/mule/input" />
    <!-- Do something with the file: here we just log its content -->
    <logger message="#[message.payloadAs(java.lang.String)]" level="ERROR" />
</flow>

<flow name="filePickupStarterFlow">
    <http:inbound-endpoint address="http://localhost:8080/file-pickup/start"
        exchange-pattern="request-response" />
    <expression-component>
        app.registry.filePickupFlow.start();
    </expression-component>
    <set-payload value="File Pickup successfully started" />
</flow>

HTTP GETting http://localhost:8080/file-pickup/start would then start the filePickupFlow, which in turn will process the files in /tmp/mule/input.

Note that it is up to you to configure the file:connector for what behavior it must have for files it processes, either deleting them or moving them to another directory are two main options.

Autres conseils

I guess in this case a File inbound to read a file on demand will not be helpful.

Please try if the follwoing way.

<flow name="flow1" doc:name="f2">
    <http:inbound-endpoint address="http://localhost:8080"
        doc:name="HTTP" exchange-pattern="request-response" />
    <component>
        <spring-object bean="fileLoader"></spring-object>
    </component>
   <file:outbound-endpoint path="C:\outputfile"
       responseTimeout="10000" doc:name="File" />
</flow>

So the Custom component will be a Class which reads the file from your specified location.

Hope this helps.

You can use Mule Requester for a clean solution. See the details in the blog entry Introducing the Mule Requester.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top