...
Maven users will need to add the following dependency to their pom.xml
for this component:
Code Block |
|
<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 format
Code Block |
spring-batch:jobName[?options]
|
...
Triggering the Spring Batch job execution:
Code Block |
|
from("direct:startBatch").to("spring-batch:myJob");
|
Triggering the Spring Batch job execution with the JobLauncher
set explicitly.
Code Block |
|
from("direct:startBatch").to("spring-batch:myJob?jobLauncherRef=myJobLauncher");
|
Starting from the Camel 2.11.1 JobExecution
instance returned by the JobLauncher
is forwarded by the SpringBatchProducer
as the output message. You can use the JobExecution
instance to perform some operations using the Spring Batch API directly.
Code Block |
|
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();
|
...
For example the snippet below configures Spring Batch to read data from JMS queue.
Code Block |
|
<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>
|
...
For example the snippet below configures Spring Batch to read data from JMS queue.
Code Block |
|
<bean id="camelReadercamelwriter" class="org.apache.camel.component.spring.batch.support.CamelItemReaderCamelItemWriter">
<constructor-arg ref="consumerTemplateproducerTemplate"/>
<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>
|
...
For example the snippet below performs simple processing of the batch item using the Direct endpoint and the Simple _expression_ language .
Code Block |
|
<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>
|
...
The example snippet below sends Spring Batch job execution events to the JMS queue.
Code Block |
|
<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>
|