简体   繁体   中英

Mule4 using read connector to read a file

I am very new to Mule4 and using it for the first time. I am trying to move a file from one directory to another. I have a "Read file" connector and "Write file" connector. In the Read connector, I specified the file path and the working directory. on the Write connector, I also specified the working directory and the path. However, the file is not moved from the source to target directory. But if I add an HTTP listener at the beginning of the flow, then it will work if I access it through http://localhost:8081 . But I want to know how can I accomplish this whenever there is a new file in the source, so the flow automatically moves the file from source to target directory? Please see the screenshot

此流不起作用

这个流程有效

You need something to trigger the flow to run. file:read doesn't do this automatically that's why http requests to trigger works for you.

All flows need a 'Source' to trigger them unless you are calling them from other flows using flow-ref (or from dataweave using a lookup()).

If you know the exact file you want then you can put a scheduler before your file:read to trigger the flow:

<scheduler>
  <scheduling-strategy>
    <fixed-frequency startDelay="5" frequency="10" timeUnit="SECONDS"/>
  </scheduling-strategy>
</scheduler>

Or you can use a file:listener to listen for new files in a directory etc as the source directly:

<flow name="onNewFile">
  <file:listener config-ref="file" directory="test-data/in" autoDelete="true">
    <scheduling-strategy>
      <fixed-frequency frequency="1000"/>
    </scheduling-strategy>
  </file:listener>
  ...
</flow>

You can use fixed frequency or cron. More details here: https://docs.mulesoft.com/mule-runtime/4.1/scheduler-xml-reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM