I have a Spring Boot application based on Spring Integration FTP where I can DOWNLOAD/UPLOAD files.
I need to send the files (as ZIP) received via mail but the problem is, I can only do this per message a file received which means if I receive 100 files, the email recipient would receive 100 emails. This is because Spring Integration processes the messages one after the other.
I need a way to aggregate the files received per poll and send to the recipient instead of sending the files one after the other.
I have tried to come up with some ideas such as these:
- move the files received to a temporary location as they are received, check when the poll is done, zip the files in this temporary location, and send them to the recipient.
- Find out how to know files received per poll.
Please can someone advise on how I can implement this:
public IntegrationFlow createIntFlow(MessageDirectory directory, ConcurrentMetadataStore metadataStore) {
var directoryName = directory.getDirectoryName();
var integrationFlowBuilder = IntegrationFlows
.from(getInboundAdapter(directory, metadataStore),
e -> e.id(directoryName + "-PerPoller")
.autoStartup(true)
.poller(Pollers
.cron(directory.getSchedule())
.taskExecutor(simpleAsyncTaskExecutor)
.errorChannel("errorChannel")
.maxMessagesPerPoll(-1)))
.log()
**integrationFlowBuilder.publishSubscribeChannel(s -> {
s.subscribe(sf -> sf.handle(c -> emailEmitter.createFileEvent(directory, c.getPayload().toString())));**
});
});
}
return integrationFlowBuilder.get();
}```