You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/06/07 09:29:47 UTC

camel git commit: Added camel-spring-batch docs to Gitbook

Repository: camel
Updated Branches:
  refs/heads/master da30baef3 -> 1b3c70f7b


Added camel-spring-batch docs to Gitbook


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1b3c70f7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1b3c70f7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1b3c70f7

Branch: refs/heads/master
Commit: 1b3c70f7b42c2749fbad7a6be579745ccded97b6
Parents: da30bae
Author: Andrea Cosentino <an...@gmail.com>
Authored: Tue Jun 7 11:29:11 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue Jun 7 11:29:11 2016 +0200

----------------------------------------------------------------------
 .../src/main/docs/spring-batch.adoc             | 267 +++++++++++++++++++
 docs/user-manual/en/SUMMARY.md                  |   1 +
 2 files changed, 268 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1b3c70f7/components/camel-spring-batch/src/main/docs/spring-batch.adoc
----------------------------------------------------------------------
diff --git a/components/camel-spring-batch/src/main/docs/spring-batch.adoc b/components/camel-spring-batch/src/main/docs/spring-batch.adoc
new file mode 100644
index 0000000..5c9182a
--- /dev/null
+++ b/components/camel-spring-batch/src/main/docs/spring-batch.adoc
@@ -0,0 +1,267 @@
+[[SpringBatch-SpringBatchComponent]]
+Spring Batch Component
+~~~~~~~~~~~~~~~~~~~~~~
+
+The *spring-batch:* component and support classes provide integration
+bridge between Camel and http://www.springsource.org/spring-batch[Spring
+Batch] infrastructure.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<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>
+------------------------------------------------------------
+
+[[SpringBatch-URIformat]]
+URI format
+^^^^^^^^^^
+
+[source,java]
+------------------------------
+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.
+
+[[SpringBatch-Options]]
+Options
+^^^^^^^
+
+
+// component options: START
+The Spring Batch component supports 1 options which are listed below.
+
+
+
+{% raw %}
+[width="100%",cols="2s,1m,8",options="header"]
+|=======================================================================
+| Name | Java Type | Description
+| jobLauncher | JobLauncher | Explicitly specifies a JobLauncher to be used.
+|=======================================================================
+{% endraw %}
+// component options: END
+
+
+
+// endpoint options: START
+The Spring Batch component supports 5 endpoint options which are listed below:
+
+{% raw %}
+[width="100%",cols="2s,1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Default | Java Type | Description
+| jobName | producer |  | String | *Required* The name of the Spring Batch job located in the registry.
+| jobFromHeader | producer |  | Boolean | Explicitly defines if the jobName shouls be taken from the headers instead of the URI.
+| jobLauncher | producer |  | JobLauncher | Explicitly specifies a JobLauncher to be used.
+| exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange
+| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
+|=======================================================================
+{% endraw %}
+// endpoint options: END
+
+
+[[SpringBatch-Usage]]
+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 `JobLauncher` is manually set on the component, then use it.
+* if `jobLauncherRef` option is set on the component, then search Camel
+link:registry.html[Registry] for the `JobLauncher` with the given name.
+*Deprecated and will be removed in Camel 3.0!*
+* if there is `JobLauncher` registered in the Camel
+link:registry.html[Registry] under *jobLauncher* name, then use it.
+* if none of the steps above allow to resolve the `JobLauncher` and
+there is exactly one `JobLauncher` instance in the Camel
+link:registry.html[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.
+
+[[SpringBatch-Examples]]
+Examples
+^^^^^^^^
+
+Triggering the Spring Batch job execution:
+
+[source,java]
+---------------------------------------------------
+from("direct:startBatch").to("spring-batch:myJob");
+---------------------------------------------------
+
+Triggering the Spring Batch job execution with the `JobLauncher` set
+explicitly.
+
+[source,java]
+--------------------------------------------------------------------------------
+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.
+
+[source,java]
+---------------------------------------------------------------------------------------------------
+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();
+---------------------------------------------------------------------------------------------------
+
+[[SpringBatch-Supportclasses]]
+Support classes
+^^^^^^^^^^^^^^^
+
+Apart from the Component, Camel Spring Batch provides also support
+classes, which can be used to hook into Spring Batch infrastructure.
+
+[[SpringBatch-CamelItemReader]]
+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.
+
+[source,xml]
+-----------------------------------------------------------------------------------------------
+<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>
+-----------------------------------------------------------------------------------------------
+
+[[SpringBatch-CamelItemWriter]]
+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.
+
+[source,xml]
+-----------------------------------------------------------------------------------------------
+<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>
+-----------------------------------------------------------------------------------------------
+
+[[SpringBatch-CamelItemProcessor]]
+CamelItemProcessor
+++++++++++++++++++
+
+`CamelItemProcessor` is the implementation of Spring Batch
+`org.springframework.batch.item.ItemProcessor` interface. The latter
+implementation relays on
+http://camel.apache.org/request-reply.html[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 http://camel.apache.org/direct.html[Direct endpoint] and
+the http://camel.apache.org/simple.html[Simple expression language].
+
+[source,xml]
+-------------------------------------------------------------------------------------------------------------
+<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>
+-------------------------------------------------------------------------------------------------------------
+
+[[SpringBatch-CamelJobExecutionListener]]
+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.
+
+[source,xml]
+-----------------------------------------------------------------------------------------------------------------------
+<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>
+-----------------------------------------------------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/camel/blob/1b3c70f7/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index c1db6c8..e888d7b 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -246,6 +246,7 @@
     * [Spark-Rest](spark-rest.adoc)
     * [Splunk](splunk.adoc)
     * [Spring](spring.adoc)
+    * [Spring Batch](spring-batch.adoc)
     * [Spring Event](spring-event.adoc)
     * [Telegram](telegram.adoc)
     * [Twitter](twitter.adoc)