问题
I have a Spring Boot scheduler that calls an Apache Camel Route. The Route reads a directory and transfers the files in that directory to another directory. Below is the Scheduler code:
@Component
public class Scheduler {
@Autowired private ProducerTemplate producerTemplate;
@Scheduled(cron = "#{@getCronValue}")
public void scheduleJob() {
System.out.println("Scheduler executing");
producerTemplate.sendBodyAndHeaders("direct:transferFile", null, null);
System.out.println("Scheduler complete");
}
}
Below is the Apache Camel route
@Component
public class FileTransferRoute extends RouteBuilder {
@Autowired private BeforeProcessor beforeProcessor;
@Override
public void configure() {
errorHandler(defaultErrorHandler()
.maximumRedeliveries(3)
.redeliverDelay(1000)
.retryAttemptedLogLevel(LoggingLevel.WARN));
from("direct:transferFile")
.log("Route reached")
.process(beforeProcessor)
.log("Input endpoint: ${exchangeProperty.inputEndpoint}")
.log("Output endpoint: ${exchangeProperty.outputEndpoint}")
.pollEnrich().simple("${exchangeProperty.inputEndpoint}")
.recipientList(exchangeProperty("outputEndpoint"))
.end();
}
}
The Processor only sets the two properties on Exchange. Here one file is transferred in each poll and the next poll transfers the next file. Example if there are three files in the directory, the first poll only transfers the first file, the next poll after 20 secs transfers the second file and so on. I want all the three files to be transferred in one poll and the next poll will transfer if more files are produced in the input directory by some other program. Can anyone please help how to achieve this?
来源:https://stackoverflow.com/questions/57907062/read-all-files-at-once-in-apache-camel-file-component