Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Spring Batch ComponentThe spring-batch: component and support classes provide integration bridge between Camel and Spring Batch infrastructure. Maven users will need to add the following dependency to their <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring-batch</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> URI formatspring-batch:jobName[?options] Where jobName represents the name of the Spring Batch job located in the Camel registry. This component can only be used to define producer endpoints, which means that you cannot use the Spring Batch component in a Options
UsageWhen Spring Batch component receives the message, it triggers the job execution. The job will be executed using the
All headers found in the message are passed to the ExamplesTriggering the Spring Batch job execution: from("direct:startBatch").to("spring-batch:myJob"); Triggering the Spring Batch job execution with the from("direct:startBatch").to("spring-batch:myJob?jobLauncherRef=myJobLauncher"); Starting from the Camel 2.11.1 from("direct:startBatch").to("spring-batch:myJob").to("mock:JobExecutions"); ... MockEndpoint mockEndpoint = ...; JobExecution jobExecution = mockEndpoint.getExchanges().get(0).getIn().getBody(JobExecution.class); BatchStatus currentJobStatus = jobExecution.getStatus(); Support classesApart from the Component, Camel Spring Batch provides also support classes, which can be used to hook into Spring Batch infrastructure. CamelItemReader
For example the snippet below configures Spring Batch to read data from JMS queue. <bean id="camelReader" class="org.apache.camel.component.spring.batch.support.CamelItemReader"> <constructor-arg ref="consumerTemplate"/> <constructor-arg value="jms:dataQueue"/> </bean> <batch:job id="myJob"> <batch:step id="step"> <batch:tasklet> <batch:chunk reader="camelReader" writer="someWriter" commit-interval="100"/> </batch:tasklet> </batch:step> </batch:job> CamelItemWriter
For example the snippet below configures Spring Batch to read data from JMS queue. <bean id="camelwriter" class="org.apache.camel.component.spring.batch.support.CamelItemWriter"> <constructor-arg ref="producerTemplate"/> <constructor-arg value="jms:dataQueue"/> </bean> <batch:job id="myJob"> <batch:step id="step"> <batch:tasklet> <batch:chunk reader="someReader" writer="camelwriter" commit-interval="100"/> </batch:tasklet> </batch:step> </batch:job> CamelItemProcessor
For example the snippet below performs simple processing of the batch item using the Direct endpoint and the Simple expression language . <camel:camelContext> <camel:route> <camel:from uri="direct:processor"/> <camel:setExchangePattern pattern="InOut"/> <camel:setBody> <camel:simple>Processed ${body}</camel:simple> </camel:setBody> </camel:route> </camel:camelContext> <bean id="camelProcessor" class="org.apache.camel.component.spring.batch.support.CamelItemProcessor"> <constructor-arg ref="producerTemplate"/> <constructor-arg value="direct:processor"/> </bean> <batch:job id="myJob"> <batch:step id="step"> <batch:tasklet> <batch:chunk reader="someReader" writer="someWriter" processor="camelProcessor" commit-interval="100"/> </batch:tasklet> </batch:step> </batch:job> CamelJobExecutionListener
The The example snippet below sends Spring Batch job execution events to the JMS queue. <bean id="camelJobExecutionListener" class="org.apache.camel.component.spring.batch.support.CamelJobExecutionListener"> <constructor-arg ref="producerTemplate"/> <constructor-arg value="jms:batchEventsBus"/> </bean> <batch:job id="myJob"> <batch:step id="step"> <batch:tasklet> <batch:chunk reader="someReader" writer="someWriter" commit-interval="100"/> </batch:tasklet> </batch:step> <batch:listeners> <batch:listener ref="camelJobExecutionListener"/> </batch:listeners> </batch:job> |