William Stevenson
William Stevenson

Reputation: 23

Spring Integration File Inbound Adapter Scan Directory Each Poll

I would like to enhance my current file inbound channel adapter that will scan the directory to refresh the file listing in the queue for each poll.

Below are the XML config for my current file inbound channel adapter :

<int-file:inbound-channel-adapter id="hostFilesOut" channel="hostFileOutChannel"
    directory="${hostfile.dir.out}" prevent-duplicates="false"
    filename-regex="${hostfile.out.filename-regex}" >
    <int:poller id="poller" cron="${poller.cron:0,4,8,12,16,20,24,28,32,36,40,44,48,52,56 * * * * * }"
        max-messages-per-poll="1" />
</int-file:inbound-channel-adapter> 

I have try to create a custom scanner to read file. However, using the scanner to a file inbound channel adapter will cause the cron configuration not working.

Can someone give an advice on this or is there any other way can also achieve the same goal.

Thank you.

Upvotes: 1

Views: 1298

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

The FileReadingMessageSource has already such an option:

/**
 * Optional. Set this flag if you want to make sure the internal queue is
 * refreshed with the latest content of the input directory on each poll.
 * <p>
 * By default this implementation will empty its queue before looking at the
 * directory again. In cases where order is relevant it is important to
 * consider the effects of setting this flag. The internal
 * {@link java.util.concurrent.BlockingQueue} that this class is keeping
 * will more likely be out of sync with the file system if this flag is set
 * to <code>false</code>, but it will change more often (causing expensive
 * reordering) if it is set to <code>true</code>.
 *
 * @param scanEachPoll
 *            whether or not the component should re-scan (as opposed to not
 *            rescanning until the entire backlog has been delivered)
 */
public void setScanEachPoll(boolean scanEachPoll) {

However I'm surprised that we don't have that option exposed for the XML configuration although that option is there since day first https://jira.spring.io/browse/INT-583.

Here is a Doc on the matter.

As a workaround you can create FileReadingMessageSource bean and use it as a ref in the <int:inbound-channel-adapter>. Another way to proceed is Annotations or Java DSL configuration. You can find some sample in the Doc mentioned above.

For the XML support, please, raise a JIRA and we will add such a XSD definition. Also don't hesitate providing contribution on the matter!

Upvotes: 1

Related Questions