Himanshu Yadav
Himanshu Yadav

Reputation: 13585

Apache Camel integration with Spring Batch

Does Apache Camel supports Spring Batch? I am my batch using Camel routes. Now we want to migrate to Spring Batch but not sure if my camel routes can integrate with Spring batch.

Upvotes: 3

Views: 9291

Answers (2)

Prakhyat
Prakhyat

Reputation: 1019

Consider a case, where a dropped file has to be picked from a folder and processed. The combination of apache camel and spring batch can solve this integration with minimal piece of code. With simple camel DSL code.

Apache Camel to solve integration problem and Spring Batch to process in a batch mode.

For integration apache camel route is required and for batch processing spring batch job is required.

More details,

Apache Camel Route will be built to pick any dropped csv file and trigger a spring batch.

**Note:**I am not providing details of what will Spring Batch Job will do. Suppose its a JOB just to process the file.

@Value("${dir.location}")
private String dropLocation;

@Override
public void configure() throws Exception {

    from(
            "file:"
                    + dropLocation
                    + "?delay=550&include=.*.csv&moveFailed=error")
            .to("spring-batch:anyFileProcessingJob?jobLauncherRef=fileProcessingJobLauncher");
}

Apache Camel is configured with a route above, to pick any files dropped in a folder "dropLocation". Camel will keep an eye on the folder and if any file dropped, a Spring Batch JOB will be triggered.

Here any file dropped in configured folder "dropLocation", camel will trigger job anyFileProcessingJob and job launch reference will be fileProcessingJobLauncher.

The "fileProcessingJobLauncher" will in run the batch job and if required necessary parameters can be passed to job from "fileProcessingJobLauncher".

Upvotes: 1

Petter Nordlander
Petter Nordlander

Reputation: 22279

Updated answer: Spring batch is supported as of Camel 2.10,

http://camel.apache.org/springbatch.html

Essentially the Spring Batch component in Camel will be able to trigger Spring batch jobs form a route.

Example: from("direct:startBatch").to("spring-batch:myJob"); where "myJob" is spring batch job defined elsewhere.

All Camel headers in the exchange are sent as parameter to the spring batch job.

Upvotes: 5

Related Questions