1

How to poll multiple files from a particular file directory using Spring Integration Api without xml configuration preferably using Java annotations based approach? I want to get the polled files list and iterate through them and process further. This is the requirement. Any Sample Code available to meet this requirement. Thanks in Advance. Below is the code fragment I used.

    @Bean    
    @InboundChannelAdapter(value = "fileInputChannel", poller = @Poller(fixedDelay = "60000",maxMessagesPerPoll="5"))     
public MessageSource<File> fileReadingMessageSource() {    
    txtSource = new FileReadingMessageSource();   
    txtSource.setDirectory(inputDir);   
    txtSource.setFilter(new SimplePatternFileListFilter("*.txt"));  
    txtSource.setScanEachPoll(true);  
        return txtSource;  
}  
     @Bean     
     @Transformer(inputChannel = "fileInputChannel", outputChannel = "processFileChannel")  
        public FileToStringTransformer fileToStringTransformer() {  
            Message<File> message1 = txtSource.receive();  
            File file1 = message1.getPayload();  
            return new FileToStringTransformer();  
        }    

But irrespective of no of files in the input dir the message source instance always fetch only one file. Not sure how to make it work for multiple files to be fetched.

1 Answers1

-1

You can try adding a task-executor to your implementation Follow this post for polling multiple files concurrently, but it doesn't follow the annotation based approach. And this post for sequential polling of files. And this also involves the use of annotations.

Community
  • 1
  • 1
Akash Mishra
  • 682
  • 1
  • 5
  • 13