Reading of files with max-messages-per-poll=10 and prevent-duplicates=false

4.6k views Asked by At

I'm trying to read files from the directory. If file cannot be processed it stays there to be tried later.

<file:inbound-channel-adapter prevent-duplicates="false" id="fileInput" directory="file:${java.io.dir}/input-data" auto-create-directory="true" filter="compositeFileFilterBean"/>

    <integration:poller id="poller" max-messages-per-poll="10" default="true" >
        <integration:interval-trigger interval="60" time-unit="SECONDS" />
    </integration:poller>

The problem is if max-messages-per-poll set to, say 10, then each poll will return exactly 10 messages, even if there is only 1 file (i.e. all 10 messages will be the same).

2

There are 2 answers

0
Gary Russell On BEST ANSWER

Yes, that would be the expected behavior with those settings.

I am not sure why you think that is wrong.

If there is a file in the directory that is not filtered by a filter (such as the one that prevents duplicates), it will be found by the poller, either within the current poll (when max-messages-per-poll is > 1) or on the next poll.

To do what you want, you would need a custom filter, that would filter a file that was previously found within your 60 seconds polling interval.

0
carmencalle On

You can: Option1. set the property "prevent-duplicates" to true in inbound-channel-adapter. This property is true by default AND in case no other filter is in place, or file-regex. If we are using a custom filter, springs understand that our custom filter will include AcceptOnceFileListFilter, so it sets prevent-duplicates to false.

Option2. complete bean "compositeFileFilterBean" with filter org.springframework.integration.file.filters.AcceptOnceFileListFilter"