Search code examples
csvmulesplitter

Processing files line by line in mule


I have a requirement in my project to process a csv file line by line. Each line of csv is going t call a rest api, get data from the api and build output payload and finally write a file.

So suppose I have 10 lines in the csv file, each line will call api, get data from api and at the end write new xml output file with 10 segments.

So could you please suggest which component would be best to achive the splitting of csv file into each line. I assume splitter or foreach can serve the purpose. But I am not 100% sure. Any help or pointer is appreciated.

TIA


Solution

  • The below code works for me

    <configuration doc:name="Configuration">
    <expression-language autoResolveVariables="true">
        <import class="org.mule.util.StringUtils" />
    </expression-language>
    </configuration>
    
    <flow name="muleutilFlow6">
    <file:inbound-endpoint path="C:\path\input sample" connector-ref="File" responseTimeout="10000" doc:name="File"/>
    <object-to-string-transformer />
    <splitter expression="#[StringUtils.split(message.payload, '\n\r')]" doc:name="Splitter" />
        <logger message="Line - #[payload]" level="INFO" doc:name="Logger"/>