5
votes

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>
1

1 Answers

12
votes

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