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