Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
Chapter 93. SpringBatch
Spring Batch Component 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The 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:
URI format 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
spring-batch:jobName[?options]
spring-batch:jobName[?options]
Where jobName represents the name of the Spring Batch job located in the Camel registry.
Warning
This component can only be used to define producer endpoints, which means that you cannot use the Spring Batch component in a
from() statement.
Options 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
| Name | Default Value | Description |
|---|---|---|
jobLauncherRef
|
null
|
*Camel 2.10:* Explicitly specifies the name of the JobLauncher to be used.
|
Usage 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
When Spring Batch component receives the message, it triggers the job execution. The job will be executed using the
org.springframework.batch.core.launch.JobLaucher instance resolved according to the following algorithm:
- if
JobLauncheris manually set on the component, then use it. - if
jobLauncherRefoption is set on the component, then search Camel Registry for theJobLauncherwith the given name. - if there is
JobLauncherregistered in the Camel Registry under jobLauncher name, then use it. - if none of the steps above allow to resolve the
JobLauncherand there is exactly oneJobLauncherinstance in the Camel Registry, then use it.
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.
Examples 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Triggering the Spring Batch job execution:
from("direct:startBatch").to("spring-batch:myJob");
from("direct:startBatch").to("spring-batch:myJob");
Triggering the Spring Batch job execution with the
JobLauncher set explicitly.
from("direct:startBatch").to("spring-batch:myJob?jobLauncherRef=myJobLauncher");
from("direct:startBatch").to("spring-batch:myJob?jobLauncherRef=myJobLauncher");
Support classes 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Apart from the Component, Camel Spring Batch provides also support classes, which can be used to hook into Spring Batch infrastructure.
CamelItemReader 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
CamelItemReader 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.
CamelItemWriter 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
CamelItemWriter 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.
CamelItemProcessor 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
CamelItemProcessor 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.
CamelJobExecutionListener 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
CamelJobExecutionListener 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.