Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mule File Inbound Polling Configuration

Tags:

mule

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>
like image 425
user2181841 Avatar asked Mar 21 '13 12:03

user2181841


People also ask

In which mule4 connector the distributed file polling feature is enabled by default?

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.

What is polling frequency in MuleSoft?

By default, Poll Scopes in Mule are set to poll a resource every 1000 milliseconds for new data.

What is the polling mechanism in MuleSoft?

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.”


1 Answers

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

like image 86
Daniel Avatar answered Oct 10 '22 20:10

Daniel