I want to poll 10 files at a time at certain time intervals from a particular directory. If there exists 250 files in that directory Mule file inbound should take 10 files out of 250 and process them then again 10 files etc.. I have polling frequence value "10000"
I tried to apply maxThreadsActive like this but it doesnt work
<file:connector>
<receiver-thread-profile maxThreadsActive=10/>
</file:connector>
In Mule 4, distributed file polling makes it possible to poll files in all cluster nodes. Enabled by default, this feature is used by the following connectors: File Connector. FTP Connector.
By default, Poll Scopes in Mule are set to poll a resource every 1000 milliseconds for new data.
MuleSoft allows developers to do this via “Poll Scope.” The poll scope feature allows the developer to poll a particular source endpoint based on a timed interval. The poll scope also has this neat caching function known as “watermark.”
Mule lets you override certain parts of the transport implementation. In this case you should override org.mule.transport.file.FileMessageReceiver
, specifically listFiles()
method.
public class MyFileMessageReceiver extends FileMessageReceiver
{
private static final MAX_FILES = 10;
@Override
List<File> listFiles() throws MuleException
{
try
{
List<File> files = new ArrayList<File>();
this.basicListFiles(readDirectory, files);
if(files.isEmpty())
return NO_FILES;
if(files.size() > MAX_FILES)
return files.subList(0, MAX_FILES);
else
return files;
}
catch (Exception e)
{
throw new DefaultMuleException(FileMessages.errorWhileListingFiles(), e);
}
}
}
Then, create a connector that will use your message receiver
<file:connector name="inboundFileConnector">
<service-overrides messageReceiver="org.mule.transport.file.MyFileMessageReceiver"/>
</file:connector>
Finally you can use this connector with any file inbound endpoint in your config. You just have to specify the polling frequency and you're done.
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With