Search code examples
anypoint-studiomulesoftmule4

How to set schedule and merge file in Anypoint Studio(MuleSoft)


I would like to set time schedule and merge file by using MuleSoft Anypoint Studio.

Example: The file name (folder name)input/a.txt includes

1, 2, 3

and the other file name is (folder name)output/b.txt which includes

4, 5, 6

and I would like to merge contents of a.txt file into b.txt at next day of 0AM file like below:

b.txt

4, 5, 6
1, 2, 3

I think to work out this problem just using Schedule/Write function but I couldn't.

Can anyone please help to resolve this?


Solution

  • It is correct that using the Scheduler component, and the File connector's read and write operations you can achieve that. I wrote an example below. For the output file you have to set the write mode to APPEND, so the existing contents are not overwritten. Note that for this to work the input files need to have an end of line at the end of the record.

    Note that Anypoint Studio is an IDE. It will not implement anything, however you can use it to develop a Mule application that will implement your requirements. The application will be executed by Mule Runtime, inside Studio or in some other environment.

    <file:config name="File_Config" doc:name="File Config" />
    <flow name="test-file-appendFlow" >
        <scheduler doc:name="Scheduler" >
            <scheduling-strategy >
                <fixed-frequency frequency="1" timeUnit="DAYS"/>
            </scheduling-strategy>
        </scheduler>
        <file:read doc:name="Read" config-ref="File_Config" path="/tmp/input/a.txt"/>
        <file:write doc:name="Write" config-ref="File_Config" path="/tmp/output/b.txt" mode="APPEND"/>
    </flow>