1

I have configured spring integration to poll a directory. I have configured InBoundChannelAdaptor with poller configuration of

maxMessagesPerPoll = -1 trigger = PeriodicTrigger(1000)

Also I have provided custom comparator while creating the FileReadingMessageSource, to process the files based on modification datetime.

    FileReadingMessageSource source = new FileReadingMessageSource(new Comparator<File>(){
    
    @Override
    public int compare(File a , File b)
    {
            if(a.lastModified() > b.lastModified())
            {
                   return 1;
            }else{
                    return -1;
            }
    }


})

My folder is having 2000 files, but files are not processing in the lastModified manner, means the oldest file should process first, but it is not happening.

Kshitiz
  • 21
  • 3
  • We probably need to know more about your downstream processing. Perhaps you do some thread shifting over there breaking the mentioned order. – Artem Bilan Dec 23 '21 at 13:31
  • As of now, doing nothing, just printing the filename to check. Also, if I remove the custom ordering, by default as per the Spring Docs, it processes in Natural Ordering of path, which is working perfectly fine. But what I want is file should get process in FIFO order instead of natural ordering of path. – Kshitiz Dec 24 '21 at 05:31

1 Answers1

1

This works for me as expected:

@Bean
IntegrationFlow lastModifiedOrderFlow() {
    return IntegrationFlows.from(
                    Files.inboundAdapter(new File(System.getProperty("user.home") + "/Downloads"),
                            Comparator.comparingLong(File::lastModified)),
                    e -> e.poller(p -> p.fixedDelay(1000).maxMessagesPerPoll(-1)))
            .handle(m -> System.out.println(m.getPayload()))
            .get();
}

We probably need to know more about your setup.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118