Search code examples
mulesftpoutbound

Mule - Send SFTP outbound message after Collection Split


I am using collection-splitter to split my List. Now how should I set the payload to SFTP outbound-endpoint.

        <sftp:inbound-endpoint connector-ref="sftp-inbound" host="${SFTP_HOST}" port="${SFTP_PORT}" 
        path="/files/" user="${SFTP_USER}" password="${SFTP_PASS}" 
        responseTimeout="10000" pollingFrequency="30000" fileAge="20000" sizeCheckWaitTime="5000" 
        archiveDir="/files/archive/" doc:name="SFTP"  >
             <file:filename-regex-filter pattern="Test(.*).zip" caseSensitive="true"/>
        </sftp:inbound-endpoint>

        <set-variable variableName="regexVal" value="${REGEX}" doc:name="Variable"/>
        <set-variable variableName="sourceFileName" value="#[flowVars.originalFilename]" doc:name="Variable"/>

        <custom-transformer name="zipTxt" class="com.mst.transform.UnzipTransformer" doc:name="Java" mimeType="image/gif">
            <spring:property name="filenamePattern" value="*.csv,*.txt" />
        </custom-transformer>

        <set-variable variableName="fileContents" value="#[payload]" />

        <collection-splitter enableCorrelation="IF_NOT_SET" />

        <logger message="#[payload]" level="INFO" doc:name="Logger"/>

        <sftp:outbound-endpoint connector-ref="sftp-inbound" 
            host="${SFTP_HOST}" port="${SFTP_PORT}" 
            path="/files/" user="${SFTP_USER}" password="${SFTP_PASS}"  
            responseTimeout="10000" doc:name="SFTP" 
            exchange-pattern="one-way"/>

 </flow>

Solution

  • If your payload before collection splitter is list of objects that can be consumed by SFTP outbound endpoint like InputStream, then after splitter, you can wrap logger, sftp inside processor-chain. Splitter will send each object one-by-one to processor chain. SFTP should be able to write it if its an InputSream.

    <collection-splitter enableCorrelation="IF_NOT_SET" />
    
    <processor-chain doc:name="Processor Chain">
            <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    
            <sftp:outbound-endpoint connector-ref="sftp-inbound" 
                host="${SFTP_HOST}" port="${SFTP_PORT}" 
                path="/files/" user="${SFTP_USER}" password="${SFTP_PASS}"  
                responseTimeout="10000" doc:name="SFTP" 
                exchange-pattern="one-way"/>
    </processor-chain>
    

    You wouldn't need processor-chain if you just want to put one processor (eg. SFTP) after splitter.

    If this doesn't work, then please add error details to question.