Read all files at once in Apache Camel file component

牧云@^-^@ 提交于 2019-12-11 15:38:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!