0
votes

I have an orchestration flow which calls a subflow to write the file and then next flow (via flow ref) to sftp it.

WriteSubflow

 <file:outbound-endpoint path="${outputDir}" outputPattern="${fileName}" responseTimeout="10000" doc:name="Write file"/>

 <logger message="File ${fileName}  written to ${outputDir}" level="INFO" doc:name="End"/>

Then I call a flow (via ref) which kicks off sftp process.

<flow name="sftp">
    <file:inbound-endpoint path="${outputDir}" connector-ref="File" responseTimeout="10000" doc:name="File">
        <file:filename-regex-filter pattern="${fileName}" caseSensitive="true"/>
    </file:inbound-endpoint>
    <sftp:outbound-endpoint exchange-pattern="one-way" connector-ref="SFTP"  responseTimeout="10000" ref="endpoint" doc:name="SFTP"  />
</flow>

The problem is

  1. While the file is being written, the flow executes the logger after the file outbound endpoint and says file is already written, and after a while the fileconnector spits out "Write file to ...". How do i make logger wait for file to be done writing??

  2. The file inbound endpoint in flow sftp above, is executed immiediately and file isnt ready yet. so it throws an exception first saying its expecting a InputStream or byte[] or String but got a ArrayList(which is original payload from the orchestration flow). After this exception is printed, finally the file is ready and the inbound file connector kicks off reads it and sftps it fine. This seems related to above question where I need to somehow make the rest of the flow wait for file writing to finish.

Note: I have to create sftp flow as a flow instead of subflow, because it needs to be a source. I think if I dont create it a flow and have file connector not as a source, it will become outbound connector.

Any help appreciated.

2

2 Answers

2
votes

So i finally figured it out, somehow both these questions are answered in one blog post here http://www.sixtree.com.au/articles/2015/advanced-file-handling-in-mule/

The key for #1 is

 <file:connector name="synchronous-file-connector" doc:name="File">
     <dispatcher-threading-profile doThreading="false"/>
</file:connector>

For #2 as Ryan mentions above, using mule requester module.

1
votes

1) Set the Flow's procesingStrategy to synchronous:

<flow name="testFlow" processingStrategy="synchronous">
        <poll frequency="10000">
            <set-payload value="some test text" />
        </poll>

        <file:outbound-endpoint path="/Users/ryancarter/Downloads"
            outputPattern="test.txt" />

        <logger level="ERROR" message="After file..." />
</flow>

2) Not sure I quite understand, but you cant invoke inbound-endpoints via flow-ref so the inbound-endpoint will be ignored and the inbound endpoint will run on its own regardless of the calling flow. If you want to read in the file mid-flow then using the mule-requestor module: http://blogs.mulesoft.com/introducing-the-mule-requester-module/