amar singh
amar singh

Reputation: 47

Process parallel multiple read in spring Integration

I have one file which contains some record and i have second file which also contains same record but with more details , so i want to process in a way that read one record from first file and search in second. How to read two files in parallel ?

Update :

return IntegrationFlows.from(readFilefromDirectory(), fileInboundPollingConsumer())
                    .split(fileSplitter())
                .channel(c ->c.executor(id, executor))

here in first line we are reading first file and then splitting it sending to executer channel so i want to know where should i write logic to read second file means to read from directory and then search record in that excel file .

Upvotes: 0

Views: 259

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121482

All the parallel work in Spring Integration can be done via ExecutorChannel.

I'd suggest to use FileSplitter for the first file and an ExecutorChannel as an output.

As for the second file... Well, I'd read it once into the memory e.g. as a Map if you have some delimiter between record and its details. And use that memory store for incoming record.

UPDATE

If the second file is very big, you can do like this:

Scanner scanner=new Scanner(file);
while(scanner.hasNextLine()) {
     String line = scanner.nextLine();
     if(line.startsWith(payload)) {
        return line;
      }
 }

UPDATE 2

return IntegrationFlows.from(readFilefromDirectory(), fileInboundPollingConsumer())
            .split(fileSplitter())
            .channel(c ->c.executor(id, executor))
            .handle("searchService", "searchMethod")

where searchService is some service @Bean (or just @Service) and searchMethod utilize logic to accept the String line and implement logic to do the search in other file. That search operation will be done in parallel for each splitted like.

The logic to read Excel file is out of Spring Integration scope. That is fully different question.

Upvotes: 1

Related Questions