SpringBatchPage edited by Henryk Konsek
Comment:
Added CamelItemProcessor and CamelJobExecutionListener sections
Changes (2)
Full ContentSpring 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 pom.xml for this component: <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>
All headers found in the message are passed to the JobLauncher as job parameters. String, Long, Double and java.util.Date values are copied to the org.springframework.batch.core.JobParametersBuilder - other data types are converted to Strings. ExamplesTriggering Spring Batch job execution: from("direct:startBatch").to("spring-batch:myJob"); Triggering Spring Batch job execution with the JabLauncher set explicitly. from("direct:startBatch").to("spring-batch:myJob?jobLauncherRef=myJobLauncher"); Support classesApart from the Component, Camel Spring Batch provides also support classes to hook into Spring Batch infrastructure. CamelItemReaderCamelItemReader can be used to read batch data directly from the Camel infrastructure. 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> CamelItemWriterCamelItemWriter has similar purpose as CamelItemReader, but it is dedicated to write chunk of the processed data. 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> CamelItemProcessorCamelItemProcessor is the implementation of Spring Batch org.springframework.batch.item.ItemProcessor interface. The latter implementation relays on Request Reply pattern to delegate the processing of the batch item to the Camel infrastructure. The item to process is sent to the Camel endpoint as the body of the message. 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> CamelJobExecutionListenerCamelJobExecutionListener is the implementation of the org.springframework.batch.core.JobExecutionListener interface sending job execution events to the Camel endpoint. The org.springframework.batch.core.JobExecution instance produced by the Spring Batch is sent as a body of the message. To distinguish between before- and after-callbacks SPRING_BATCH_JOB_EVENT_TYPE header is set to the BEFORE or AFTER value. 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>
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache Camel > SpringBatch confluence
- [CONF] Apache Camel > SpringBatch confluence
- [CONF] Apache Camel > SpringBatch confluence
- [CONF] Apache Camel > SpringBatch confluence
- [CONF] Apache Camel > SpringBatch confluence