Modified: websites/production/camel/content/seda.html
==============================================================================
--- websites/production/camel/content/seda.html (original)
+++ websites/production/camel/content/seda.html Fri Aug 25 10:20:13 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: SEDA
@@ -86,101 +75,41 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="SEDA-SEDAComponent">SEDA
Component</h2><p>The <strong><code>seda:</code></strong> component provides
asynchronous <a shape="rect" class="external-link"
href="https://en.wikipedia.org/wiki/Staged_event-driven_architecture"
rel="nofollow">SEDA</a> behavior, so that messages are exchanged on a
BlockingQueue and consumers are invoked in a separate thread from the
producer.<a shape="rect" class="external-link"
href="http://www.eecs.harvard.edu/~mdw/proj/seda/"
rel="nofollow"></a></p><p>Note that queues are only visible within a
<em>single</em> <a shape="rect" href="camelcontext.html">CamelContext</a>. If
you want to communicate across <strong><code>CamelContext</code></strong>
instances (for example, communicating between Web applications), see the <a
shape="rect" href="vm.html">VM</a> component.</p><p>This component does not
implement any kind of persistence or recovery, if the VM terminates while
messages are yet to be processed. If yo
u need persistence, reliability or distributed SEDA, try using either <a
shape="rect" href="jms.html">JMS</a> or <a shape="rect"
href="activemq.html">ActiveMQ</a>.</p><div class="confluence-information-macro
confluence-information-macro-tip"><p class="title">Synchronous</p><span
class="aui-icon aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The <a shape="rect"
href="direct.html">Direct</a> component provides synchronous invocation of any
consumers when a producer sends a message exchange.</p></div></div><h3
id="SEDA-URIformat">URI format</h3><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[seda:someName[?options]
-]]></script>
-</div></div><p>Where <strong><code>someName</code></strong> can be any
string that uniquely identifies the endpoint within the current <a shape="rect"
href="camelcontext.html">CamelContext</a>.</p><p>You can append query options
to the URI in the following format:
<strong><code>?option=value&option=value&...</code></strong></p><h3
id="SEDA-Options">Options</h3><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Since</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>size</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The maximum capacity of t
he <strong>seda</strong> queue, i.e., the number of messages it can
hold.</p><p>The default value in <strong>Camel 2.2</strong> or older is
<strong><code>1000</code></strong>.</p><p>From <strong>Camel 2.3</strong>: the
size is unbounded by default.</p><p> </p><div
class="confluence-information-macro confluence-information-macro-warning"><span
class="aui-icon aui-icon-small aui-iconfont-error
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p><strong>Note:</strong> Care should
be taken when using this option. The size is determined by the value specified
<em>when the first endpoint is created</em>. Each endpoint must therefore
specify the same size.</p><p><strong>From</strong> <strong>Camel 2.11</strong>:
a validation is taken place to ensure if using mixed queue sizes for the same
queue name, Camel would detect this and fail creating the
endpoint.</p></div></div></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code
>concurrentConsumers</code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"> </td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>1</code></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p>Number of concurrent threads processing
>exchanges.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>waitForTaskToComplete</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>IfReplyExpected</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p>Option to specify whether the
>caller should wait for the asynchronous task to complete before
>continuing.</p><p>The following options are
>supported:</p><ul><li><p><strong><code>Always</code></strong></p></li><li><p><strong><code>Never</code></strong></p></li><li><p><strong><code>IfReplyExpected</code></strong></p></li></ul><p>The
> first two values are self-explanatory.</p><p>The last value,
><strong><code>IfR
eplyExpected</code></strong>, will only wait if the message is <a shape="rect"
href="request-reply.html">Request Reply</a> based.</p><p>See <a shape="rect"
href="async.html">Async</a> messaging for more details.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>timeout</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>30000</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Timeout (in milliseconds) before
a <strong>seda</strong> producer will stop waiting for an asynchronous
task to complete.</p><p>See <strong><code>waitForTaskToComplete</code></strong>
and <a shape="rect" href="async.html">Async</a> for more details.</p><p>From
<strong>Camel 2.2:</strong> you can now disable timeout by
using <strong><code>0</code></strong> or a negative
value.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>multipleConsumers</code></p></td
><td colspan="1" rowspan="1"
>class="confluenceTd"><p><strong>2.2</strong></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p>Specifies whether multiple
>consumers are allowed. If enabled, you can use <a shape="rect"
>href="seda.html">SEDA</a> for <a shape="rect" class="external-link"
>href="http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern"
>rel="nofollow">Publish-Subscribe</a> messaging. That is, you can send a
>message to the <strong>seda</strong> queue and have each consumer
>receive a copy of the message. When enabled, this option should be specified
>on every consumer endpoint.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>limitConcurrentConsumers</code></p></td><td
>colspan="1" rowspan="1"
>class="confluenceTd"><p><strong>2.3</strong></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
>rowspan="1" class=
"confluenceTd"><p>Whether to limit the number of
<strong><code>concurrentConsumers</code></strong> to the maximum of
<strong><code>500</code></strong>.</p><p>By default, an exception will be
thrown if a <strong>seda</strong> endpoint is configured with a greater
number. You can disable that check by turning this option
off.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>blockWhenFull</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>2.9</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Whether a thread that sends
messages to a full <strong>seda</strong> queue will block until the
queue's capacity is no longer exhausted. By default, an exception will be
thrown stating that the queue is full. By enabling this option, the calling
thread will instead block and wait until the message can be
accepted.</p></td></tr><tr><td colspan=
"1" rowspan="1" class="confluenceTd"><p><code>queueSize</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>2.9</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Component only:</strong> the maximum size
(capacity of the number of messages it can hold) of
the <strong>seda</strong> queue.</p><div
class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>This option is used when
<strong><code>size</code></strong> is not
specified.</p></div></div></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>pollTimeout</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>2.9.3</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td
col
span="1" rowspan="1" class="confluenceTd"><p><strong>Consumer only</strong>:
the timeout used when polling. When a timeout occurs, the consumer can check
whether it is allowed to continue running. Setting a lower value allows the
consumer to react more quickly upon shutdown.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>purgeWhenStopping</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>2.11.1</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Whether to purge the task queue when
stopping the consumer/route. This allows to stop faster, as any pending
messages on the queue is discarded.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>queue</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>2.12.0</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p>
</td><td colspan="1" rowspan="1" class="confluenceTd"><p>Define the queue
instance which will be used by <strong>seda</strong>
endpoint</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>queueFactory</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>2.12.0</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Define
the <strong><code>QueueFactory</code></strong> which could create the
queue for the <strong>seda</strong> endpoint</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>failIfNoConsumers</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>2.12.0</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Whether the producer should fail by
throwing an exception when sending to a <strong>seda<
/strong> queue with no active consumers.</p><div
class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Only one of the
options <span><strong><code>discardIfNoConsumers</code></strong></span>
and <span><strong><code>failIfNoConsumers</code></strong></span> can be enabled
at the same time.</p></div></div></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>discardIfNoConsumers</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>2.16</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Whether the producer should discard the
message (do not add the message to the queue) when sending to
a <strong>seda</strong> queue with no active
consumers.<span> </span></p><div class=
"confluence-information-macro confluence-information-macro-information"><span
class="aui-icon aui-icon-small aui-iconfont-info
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Only one of the
options <strong><code>discardIfNoConsumers</code></strong>
and <strong><code>failIfNoConsumers</code></strong> can be enabled at the
same time.</p></div></div></td></tr></tbody></table></div><h3
id="SEDA-ChoosingBlockingQueueimplementation">Choosing BlockingQueue
implementation</h3><p><strong>Available as of Camel 2.12</strong></p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<bean id="arrayQueue"
class="java.util.ArrayBlockingQueue">
- <constructor-arg index="0" value="10"> <!--
size -->
- <constructor-arg index="1" value="true"> <!--
fairness -->
+<div class="wiki-content maincontent"><h2 id="SEDA-SEDAComponent">SEDA
Component</h2><p>The <strong><code>seda:</code></strong> component provides
asynchronous <a shape="rect" class="external-link"
href="https://en.wikipedia.org/wiki/Staged_event-driven_architecture"
rel="nofollow">SEDA</a> behavior, so that messages are exchanged on a
BlockingQueue and consumers are invoked in a separate thread from the
producer.<a shape="rect" class="external-link"
href="http://www.eecs.harvard.edu/~mdw/proj/seda/"
rel="nofollow"></a></p><p>Note that queues are only visible within a
<em>single</em> <a shape="rect" href="camelcontext.html">CamelContext</a>. If
you want to communicate across <strong><code>CamelContext</code></strong>
instances (for example, communicating between Web applications), see the <a
shape="rect" href="vm.html">VM</a> component.</p><p>This component does not
implement any kind of persistence or recovery, if the VM terminates while
messages are yet to be processed. If yo
u need persistence, reliability or distributed SEDA, try using either <a
shape="rect" href="jms.html">JMS</a> or <a shape="rect"
href="activemq.html">ActiveMQ</a>.</p><parameter
ac:name="title">Synchronous</parameter><rich-text-body><p>The <a shape="rect"
href="direct.html">Direct</a> component provides synchronous invocation of any
consumers when a producer sends a message exchange.</p></rich-text-body><h3
id="SEDA-URIformat">URI format</h3><plain-text-body>seda:someName[?options]
+</plain-text-body><p>Where <strong><code>someName</code></strong> can be
any string that uniquely identifies the endpoint within the current <a
shape="rect" href="camelcontext.html">CamelContext</a>.</p><p>You can append
query options to the URI in the following format:
<strong><code>?option=value&option=value&...</code></strong></p><h3
id="SEDA-Options">Options</h3><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Since</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>size</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The maximum capacit
y of the <strong>seda</strong> queue, i.e., the number of messages it can
hold.</p><p>The default value in <strong>Camel 2.2</strong> or older is
<strong><code>1000</code></strong>.</p><p>From <strong>Camel 2.3</strong>: the
size is unbounded by
default.</p><p> </p><rich-text-body><p><strong>Note:</strong> Care should
be taken when using this option. The size is determined by the value specified
<em>when the first endpoint is created</em>. Each endpoint must therefore
specify the same size.</p><p><strong>From</strong> <strong>Camel 2.11</strong>:
a validation is taken place to ensure if using mixed queue sizes for the same
queue name, Camel would detect this and fail creating the
endpoint.</p></rich-text-body></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>concurrentConsumers</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>1</code></p></td><td colspan="1"
rowspan="1
" class="confluenceTd"><p>Number of concurrent threads processing
exchanges.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>waitForTaskToComplete</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"> </td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>IfReplyExpected</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Option to specify whether the
caller should wait for the asynchronous task to complete before
continuing.</p><p>The following options are
supported:</p><ul><li><p><strong><code>Always</code></strong></p></li><li><p><strong><code>Never</code></strong></p></li><li><p><strong><code>IfReplyExpected</code></strong></p></li></ul><p>The
first two values are self-explanatory.</p><p>The last value,
<strong><code>IfReplyExpected</code></strong>, will only wait if the message is
<a shape="rect" href="request-reply.html">Request Reply</a> based.</p><p>See <a
shape="rect" href="async.html">Async</a> messaging for
more details.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>timeout</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>30000</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Timeout (in milliseconds) before
a <strong>seda</strong> producer will stop waiting for an asynchronous
task to complete.</p><p>See <strong><code>waitForTaskToComplete</code></strong>
and <a shape="rect" href="async.html">Async</a> for more details.</p><p>From
<strong>Camel 2.2:</strong> you can now disable timeout by
using <strong><code>0</code></strong> or a negative
value.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>multipleConsumers</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>2.2</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="c
onfluenceTd"><p>Specifies whether multiple consumers are allowed. If enabled,
you can use <a shape="rect" href="seda.html">SEDA</a> for <a shape="rect"
class="external-link"
href="http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern"
rel="nofollow">Publish-Subscribe</a> messaging. That is, you can send a message
to the <strong>seda</strong> queue and have each consumer receive a copy
of the message. When enabled, this option should be specified on every consumer
endpoint.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>limitConcurrentConsumers</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>2.3</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Whether to limit the number of
<strong><code>concurrentConsumers</code></strong> to the maximum of
<strong><code>500</code></strong>.</p><p>By default, an exception will be thrown
if a <strong>seda</strong> endpoint is configured with a greater number.
You can disable that check by turning this option off.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>blockWhenFull</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>2.9</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Whether a thread that sends
messages to a full <strong>seda</strong> queue will block until the
queue's capacity is no longer exhausted. By default, an exception will be
thrown stating that the queue is full. By enabling this option, the calling
thread will instead block and wait until the message can be
accepted.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>queueSize</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>2.9</strong></p></td><td
colspan="1" rowspan="1" class="confluence
Td"> </td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Component only:</strong> the maximum size
(capacity of the number of messages it can hold) of
the <strong>seda</strong> queue.</p><rich-text-body><p>This option is used
when <strong><code>size</code></strong> is not
specified.</p></rich-text-body></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>pollTimeout</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>2.9.3</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>1000</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Consumer only</strong>:
the timeout used when polling. When a timeout occurs, the consumer can check
whether it is allowed to continue running. Setting a lower value allows the
consumer to react more quickly upon shutdown.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>purgeWhenStopping</code></p></td><td
colspan="1" row
span="1" class="confluenceTd"><p><strong>2.11.1</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Whether to purge the task queue
when stopping the consumer/route. This allows to stop faster, as any pending
messages on the queue is discarded.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>queue</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>2.12.0</strong></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Define the queue instance which
will be used by <strong>seda</strong> endpoint</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>queueFactory</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>2.12.0</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><t
d colspan="1" rowspan="1" class="confluenceTd"><p>Define
the <strong><code>QueueFactory</code></strong> which could create the
queue for the <strong>seda</strong> endpoint</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>failIfNoConsumers</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><strong>2.12.0</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Whether the producer should fail by
throwing an exception when sending to a <strong>seda</strong> queue with
no active consumers.</p><rich-text-body><p>Only one of the
options <span><strong><code>discardIfNoConsumers</code></strong></span>
and <span><strong><code>failIfNoConsumers</code></strong></span> can be enabled
at the same time.</p></rich-text-body></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>discardIfNoConsumers</code></p></td><td
colspan="1" rowsp
an="1" class="confluenceTd"><p><strong>2.16</strong></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Whether the producer should discard the
message (do not add the message to the queue) when sending to
a <strong>seda</strong> queue with no active
consumers.<span> </span></p><rich-text-body><p>Only one of the
options <strong><code>discardIfNoConsumers</code></strong>
and <strong><code>failIfNoConsumers</code></strong> can be enabled at the
same time.</p></rich-text-body></td></tr></tbody></table></div><h3
id="SEDA-ChoosingBlockingQueueimplementation">Choosing BlockingQueue
implementation</h3><p><strong>Available as of Camel 2.12</strong></p><parameter
ac:name="language">xml</parameter><plain-text-body><bean id="arrayQueue"
class="java.util.ArrayBlockingQueue">
+ <constructor-arg index="0" value="10"> <!-- size -->
+ <constructor-arg index="1" value="true"> <!-- fairness -->
</bean>
<!-- ... -->
-<from uri="seda:array?queue=#arrayQueue"/>
-]]></script>
-</div></div><p>By default, the <strong>seda</strong> component
instantiates a <strong><code>LinkedBlockingQueue</code></strong>. However, a
different implementation can be chosen by specifying a custom 
<strong><code>BlockingQueue</code></strong> implementation. When a custom
implementation is configured the <strong><code>size</code></strong> option
is ignored.</p><p>The list of
available <strong><code>BlockingQueueFactory</code></strong>
implementations
includes:</p><ul><li><strong><code>LinkedBlockingQueueFactory</code></strong></li><li><strong><code>ArrayBlockingQueueFactory</code></strong></li><li><strong><code>PriorityBlockingQueueFactory</code></strong><br
clear="none"><br clear="none"></li></ul><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<bean id="priorityQueueFactory"
class="org.apache.camel.component.seda.PriorityBlockingQueueFactory">
- <property name="comparator">
- <bean class="org.apache.camel.demo.MyExchangeComparator"/>
+<from uri="seda:array?queue=#arrayQueue"/>
+</plain-text-body><p>By default, the <strong>seda</strong> component
instantiates a <strong><code>LinkedBlockingQueue</code></strong>. However, a
different implementation can be chosen by specifying a custom 
<strong><code>BlockingQueue</code></strong> implementation. When a custom
implementation is configured the <strong><code>size</code></strong> option
is ignored.</p><p>The list of
available <strong><code>BlockingQueueFactory</code></strong>
implementations
includes:</p><ul><li><strong><code>LinkedBlockingQueueFactory</code></strong></li><li><strong><code>ArrayBlockingQueueFactory</code></strong></li><li><strong><code>PriorityBlockingQueueFactory</code></strong><br
clear="none"><br clear="none"></li></ul><parameter
ac:name="language">xml</parameter><plain-text-body><bean
id="priorityQueueFactory"
class="org.apache.camel.component.seda.PriorityBlockingQueueFactory">
+ <property name="comparator">
+ <bean class="org.apache.camel.demo.MyExchangeComparator"/>
</property>
</bean>
<!-- ...and later -->
-<from
uri="seda:priority?queueFactory=#priorityQueueFactory&size=100"/>
-<!-- ... -->Â ]]></script>
-</div></div><h3 id="SEDA-UseofRequestReply">Use of Request Reply</h3><p>The <a
shape="rect" href="seda.html">SEDA</a> component supports using <a shape="rect"
href="request-reply.html">Request Reply</a>, where the caller will wait for the
<a shape="rect" href="async.html">Async</a> route to complete. For
instance:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("mina:tcp://0.0.0.0:9876?textline=true&sync=true")
- .to("seda:input");
-
-from("seda:input")
- .to("bean:processInput")
- .to("bean:createResponse");
-]]></script>
-</div></div><p>In the route above, we have a TCP listener on
port <strong><code>9876</code></strong> that accepts incoming requests.
The request is routed to the <strong><code>seda:input</code></strong> queue. As
it is a <a shape="rect" href="request-reply.html">Request Reply</a> message, we
wait for the response. When the consumer on the
<strong><code>seda:input</code></strong> queue is complete, it copies the
response to the original message response.</p><div
class="confluence-information-macro confluence-information-macro-note"><p
class="title">until 2.2: Works only with 2 endpoints</p><span class="aui-icon
aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Using <a shape="rect"
href="request-reply.html">Request Reply</a> over <a shape="rect"
href="seda.html">SEDA</a> or <a shape="rect" href="vm.html">VM</a> only works
with 2 endpoints. You <strong>cannot</strong> chain endpoints by sending
to 
<strong><code>A -> B -> C</code></strong> etc. Only between
<strong><code>A -> B</code></strong>. The reason is the implementation logic
is fairly simple. To support 3+ endpoints makes the logic much more complex to
handle ordering and notification between the waiting threads
properly.</p><p>This has been improved in <strong>Camel 2.3</strong>, which
allows you to chain as many endpoints as you like.</p></div></div><h3
id="SEDA-Concurrentconsumers">Concurrent consumers</h3><p>By default, the SEDA
endpoint uses a single consumer thread, but you can configure it to use
concurrent consumer threads. So, instead of thread pools you can use:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("seda:stageName?concurrentConsumers=5")
+<from
uri="seda:priority?queueFactory=#priorityQueueFactory&size=100"/>
+<!-- ... --> </plain-text-body><h3 id="SEDA-UseofRequestReply">Use
of Request Reply</h3><p>The <a shape="rect" href="seda.html">SEDA</a> component
supports using <a shape="rect" href="request-reply.html">Request Reply</a>,
where the caller will wait for the <a shape="rect" href="async.html">Async</a>
route to complete. For instance:</p><parameter
ac:name="language">java</parameter><plain-text-body>from("mina:tcp://0.0.0.0:9876?textline=true&sync=true")
+ .to("seda:input");
+
+from("seda:input")
+ .to("bean:processInput")
+ .to("bean:createResponse");
+</plain-text-body><p>In the route above, we have a TCP listener on
port <strong><code>9876</code></strong> that accepts incoming requests.
The request is routed to the <strong><code>seda:input</code></strong> queue. As
it is a <a shape="rect" href="request-reply.html">Request Reply</a> message, we
wait for the response. When the consumer on the
<strong><code>seda:input</code></strong> queue is complete, it copies the
response to the original message response.</p><parameter ac:name="title">until
2.2: Works only with 2 endpoints</parameter><rich-text-body><p>Using <a
shape="rect" href="request-reply.html">Request Reply</a> over <a shape="rect"
href="seda.html">SEDA</a> or <a shape="rect" href="vm.html">VM</a> only works
with 2 endpoints. You <strong>cannot</strong> chain endpoints by sending
to <strong><code>A -> B -> C</code></strong> etc. Only between
<strong><code>A -> B</code></strong>. The reason is the implementation logic
is fairly simple. To support 3+ endpo
ints makes the logic much more complex to handle ordering and notification
between the waiting threads properly.</p><p>This has been improved in
<strong>Camel 2.3</strong>, which allows you to chain as many endpoints as you
like.</p></rich-text-body><h3 id="SEDA-Concurrentconsumers">Concurrent
consumers</h3><p>By default, the SEDA endpoint uses a single consumer thread,
but you can configure it to use concurrent consumer threads. So, instead of
thread pools you can use:</p><parameter
ac:name="language">java</parameter><plain-text-body>from("seda:stageName?concurrentConsumers=5")
.process(...)
-]]></script>
-</div></div><p>As for the difference between the two, note a <em>thread
pool</em> can increase/shrink dynamically at runtime depending on load, whereas
the number of concurrent consumers is always fixed.</p><h3
id="SEDA-Threadpools">Thread pools</h3><p>Be aware that adding a thread pool to
a <strong>seda</strong> endpoint by doing something like:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("seda:stageName")
+</plain-text-body><p>As for the difference between the two, note a <em>thread
pool</em> can increase/shrink dynamically at runtime depending on load, whereas
the number of concurrent consumers is always fixed.</p><h3
id="SEDA-Threadpools">Thread pools</h3><p>Be aware that adding a thread pool to
a <strong>seda</strong> endpoint by doing something like:</p><parameter
ac:name="language">java</parameter><plain-text-body>from("seda:stageName")
.thread(5)
.process(...)
-]]></script>
-</div></div><p>Can wind up with two <strong><code>BlockQueues</code>:</strong>
one from the <strong>seda</strong> endpoint, and one from the workqueue of
the thread pool, which may not be what you want. Instead, you might wish to
configure a <a shape="rect" href="direct.html">Direct</a> endpoint with a
thread pool, which can process messages both synchronously and asynchronously.
For example:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:stageName")
+</plain-text-body><p>Can wind up with two
<strong><code>BlockQueues</code>:</strong> one from
the <strong>seda</strong> endpoint, and one from the workqueue of the
thread pool, which may not be what you want. Instead, you might wish to
configure a <a shape="rect" href="direct.html">Direct</a> endpoint with a
thread pool, which can process messages both synchronously and asynchronously.
For example:</p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:stageName")
.thread(5)
.process(...)
-]]></script>
-</div></div><p>You can also directly configure number of threads that process
messages on a <strong>seda</strong> endpoint using the
<strong><code>concurrentConsumers</code></strong> option.</p><h3
id="SEDA-Sample">Sample</h3><p>In the route below we use the SEDA queue to send
the request to this asynchronous queue to be able to send a fire-and-forget
message for further processing in another thread, and return a constant reply
in this thread to the original caller.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-public void configure() throws Exception {
- from("direct:start")
- // send it to the seda queue that is async
- .to("seda:next")
- // return a constant response
- .transform(constant("OK"));
-
- from("seda:next").to("mock:result");
-}
-]]></script>
-</div></div>Here we send a Hello World message and expects the reply to be
OK.<div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-Object out = template.requestBody("direct:start", "Hello
World");
-assertEquals("OK", out);
-]]></script>
-</div></div>The <strong><code>Hello World</code></strong> message will be
consumed from the <strong>seda</strong> queue from another thread for
further processing. Since this is from a unit test, it will be sent to a
<strong><code>mock</code></strong> endpoint where we can do assertions in the
unit test.<h3
id="SEDA-UsingmultipleConsumers">Using <code>multipleConsumers</code></h3><p><strong>Available
as of Camel 2.2</strong></p><p>In this example we have defined two consumers
and registered them as spring beans.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<!-- define the consumers as spring beans -->
-<bean id="consumer1"
class="org.apache.camel.spring.example.FooEventConsumer"/>
-
-<bean id="consumer2"
class="org.apache.camel.spring.example.AnotherFooEventConsumer"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <!-- define a shared endpoint which the consumers can refer to instead
of using url -->
- <endpoint id="foo"
uri="seda:foo?multipleConsumers=true"/>
-</camelContext>
-]]></script>
-</div></div>Since we have specified
<strong><code>multipleConsumers=true</code></strong> on the
<strong>seda</strong> <strong><code>foo</code></strong> endpoint we can
have those two consumers receive their own copy of the message as a kind of
pub-sub style messaging.<p>As the beans are part of an unit test they simply
send the message to a <strong><code>mock</code></strong> endpoint. Note
the use of <strong><code>@Consume</code></strong> to consume from the
<strong>seda</strong> queue.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-public class FooEventConsumer {
-
- @EndpointInject(uri = "mock:result")
- private ProducerTemplate destination;
-
- @Consume(ref = "foo")
- public void doSomething(String body) {
- destination.sendBody("foo" + body);
- }
-
-}
-]]></script>
-</div></div><h3 id="SEDA-ExtractingQueueInformation.">Extracting Queue
Information.</h3><p>If needed, information such as queue size, etc. can be
obtained without using JMX in this fashion:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[SedaEndpoint seda =
context.getEndpoint("seda:xxxx");
+</plain-text-body><p>You can also directly configure number of threads that
process messages on a <strong>seda</strong> endpoint using the
<strong><code>concurrentConsumers</code></strong> option.</p><h3
id="SEDA-Sample">Sample</h3><p>In the route below we use the SEDA queue to send
the request to this asynchronous queue to be able to send a fire-and-forget
message for further processing in another thread, and return a constant reply
in this thread to the original caller.<parameter
ac:name="atlassian-macro-output-type">INLINE</parameter><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaAsyncRouteTest.java}</plain-text-body>Here
we send a Hello World message and expects the reply to be OK.<parameter
ac:name="atlassian-macro-output-type">INLINE</parameter><plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/SedaAsyncRouteTest.java}</plain-text-body>Th
e <strong><code>Hello World</code></strong> message will be consumed from
the <strong>seda</strong> queue from another thread for further
processing. Since this is from a unit test, it will be sent to a
<strong><code>mock</code></strong> endpoint where we can do assertions in the
unit test.</p><h3
id="SEDA-UsingmultipleConsumers">Using <code>multipleConsumers</code></h3><p><strong>Available
as of Camel 2.2</strong></p><p>In this example we have defined two consumers
and registered them as spring beans.<parameter
ac:name="atlassian-macro-output-type">INLINE</parameter><plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/example/fooEventRoute.xml}</plain-text-body>Since
we have specified <strong><code>multipleConsumers=true</code></strong> on the
<strong>seda</strong> <strong><code>foo</code></strong> endpoint we can
have those two consumers receive their own copy of the message as a kind of pub
-sub style messaging.</p><p>As the beans are part of an unit test they simply
send the message to a <strong><code>mock</code></strong> endpoint. Note
the use of <strong><code>@Consume</code></strong> to consume from the
<strong>seda</strong> queue.<parameter
ac:name="atlassian-macro-output-type">INLINE</parameter><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/example/FooEventConsumer.java}</plain-text-body></p><h3
id="SEDA-ExtractingQueueInformation.">Extracting Queue Information.</h3><p>If
needed, information such as queue size, etc. can be obtained without using JMX
in this fashion:</p><parameter
ac:name="language">java</parameter><plain-text-body>SedaEndpoint seda =
context.getEndpoint("seda:xxxx");
int size = seda.getExchanges().size();
-]]></script>
-</div></div><p></p><h3 id="SEDA-SeeAlso">See Also</h3>
-<ul><li><a shape="rect" href="configuring-camel.html">Configuring
Camel</a></li><li><a shape="rect"
href="component.html">Component</a></li><li><a shape="rect"
href="endpoint.html">Endpoint</a></li><li><a shape="rect"
href="getting-started.html">Getting Started</a></li></ul><ul
class="alternate"><li><a shape="rect" href="vm.html">VM</a></li><li><a
shape="rect" href="disruptor.html">Disruptor</a></li><li><a shape="rect"
href="direct.html">Direct</a></li><li><a shape="rect"
href="async.html">Async</a></li></ul></div>
+</plain-text-body><p><parameter ac:name=""><a shape="rect"
href="endpoint-see-also.html">Endpoint See Also</a></parameter></p><ul
class="alternate"><li><a shape="rect" href="vm.html">VM</a></li><li><a
shape="rect" href="disruptor.html">Disruptor</a></li><li><a shape="rect"
href="direct.html">Direct</a></li><li><a shape="rect"
href="async.html">Async</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/spring.html
==============================================================================
--- websites/production/camel/content/spring.html (original)
+++ websites/production/camel/content/spring.html Fri Aug 25 10:20:13 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Spring
@@ -86,152 +75,68 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="Spring-SpringSupport">Spring
Support</h2><p>Apache Camel is designed to work nicely with the <a shape="rect"
class="external-link" href="http://www.springframework.org/"
rel="nofollow">Spring Framework</a> in a number of ways.</p><ul><li>Camel uses
Spring Transactions as the default transaction handling in components like <a
shape="rect" href="jms.html">JMS</a> and <a shape="rect"
href="jpa.html">JPA</a></li><li>Camel works with Spring 2 XML processing with
the <a shape="rect" href="xml-configuration.html">Xml
Configuration</a></li><li>Camel Spring XML Schema's is defined at <a
shape="rect" href="xml-reference.html">Xml Reference</a></li><li>Camel supports
a powerful version of <a shape="rect" href="spring-remoting.html">Spring
Remoting</a> which can use powerful routing between the client and server side
along with using all of the available <a shape="rect"
href="components.html">Components</a> for the transport</li><li>Camel provides p
owerful <a shape="rect" href="bean-integration.html">Bean Integration</a> with
any bean defined in a Spring
<strong><code>ApplicationContext</code></strong>.</li><li>Camel integrates with
various Spring helper classes; such as providing <a shape="rect"
href="type-converter.html">Type Converter</a> support for Spring Resources
etc</li><li>Allows Spring to dependency inject <a shape="rect"
href="component.html">Component</a> instances or the <a shape="rect"
href="camelcontext.html">CamelContext</a> instance itself and auto-expose
Spring beans as components and endpoints.</li><li>Allows you to reuse the <a
shape="rect" href="spring-testing.html">Spring Testing</a> framework to
simplify your unit and integration testing using <a shape="rect"
href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a>
and Camel's powerful <a shape="rect" href="mock.html">Mock</a> and <a
shape="rect" href="test.html">Test</a>
endpoints</li><li>From <strong>Camel 2.15</strong>: Cam
el supports Spring Boot using the <code><a shape="rect"
href="spring-boot.html">camel-spring-boot</a></code>
component.</li><li>From <strong>Camel 2.17.1</strong>: Camel supports
Spring Cache based Idempotent repository</li></ul><h2
id="Spring-UsingSpringtoconfiguretheCamelContext">Using Spring to configure the
CamelContext</h2><p>You can configure
a <strong><code>CamelContext</code></strong> inside
any <strong><code>spring.xml</code></strong> using the <a shape="rect"
class="external-link"
href="http://camel.apache.org/maven/current/camel-spring/apidocs/org/apache/camel/spring/CamelContextFactoryBean.html">CamelContextFactoryBean</a>.
This will automatically <a shape="rect" href="lifecycle.html">start</a> the <a
shape="rect" href="camelcontext.html">CamelContext</a> along with any
referenced <a shape="rect" href="routes.html">Routes</a> along any referenced
<a shape="rect" href="component.html">Component</a> and <a shape="rect"
href="endpoint.html">Endpoint</a>
instances.</p><ul><li>Adding Camel schema</li><li>Configure <a shape="rect"
href="routes.html">Routes</a> in two ways:<ul><li>Using Java Code</li><li>Using
Spring XML</li></ul></li></ul><h3 id="Spring-AddingCamelSchema">Adding Camel
Schema</h3><div class="confluence-information-macro
confluence-information-macro-note"><span class="aui-icon aui-icon-small
aui-iconfont-warning confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>For Camel 1.x you need to use the
following namespace:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[http://activemq.apache.org/camel/schema/spring
-]]></script>
-</div></div><p>with the following schema location:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
-]]></script>
-</div></div></div></div><p>You need to add Camel to the
<strong><code>schemaLocation</code></strong> declaration</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
-]]></script>
-</div></div><p>So the XML file looks like this:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<beans
xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
+<div class="wiki-content maincontent"><h2 id="Spring-SpringSupport">Spring
Support</h2><p>Apache Camel is designed to work nicely with the <a shape="rect"
class="external-link" href="http://www.springframework.org/"
rel="nofollow">Spring Framework</a> in a number of ways.</p><ul><li>Camel uses
Spring Transactions as the default transaction handling in components like <a
shape="rect" href="jms.html">JMS</a> and <a shape="rect"
href="jpa.html">JPA</a></li><li>Camel works with Spring 2 XML processing with
the <a shape="rect" href="xml-configuration.html">Xml
Configuration</a></li><li>Camel Spring XML Schema's is defined at <a
shape="rect" href="xml-reference.html">Xml Reference</a></li><li>Camel supports
a powerful version of <a shape="rect" href="spring-remoting.html">Spring
Remoting</a> which can use powerful routing between the client and server side
along with using all of the available <a shape="rect"
href="components.html">Components</a> for the transport</li><li>Camel provides p
owerful <a shape="rect" href="bean-integration.html">Bean Integration</a> with
any bean defined in a Spring
<strong><code>ApplicationContext</code></strong>.</li><li>Camel integrates with
various Spring helper classes; such as providing <a shape="rect"
href="type-converter.html">Type Converter</a> support for Spring Resources
etc</li><li>Allows Spring to dependency inject <a shape="rect"
href="component.html">Component</a> instances or the <a shape="rect"
href="camelcontext.html">CamelContext</a> instance itself and auto-expose
Spring beans as components and endpoints.</li><li>Allows you to reuse the <a
shape="rect" href="spring-testing.html">Spring Testing</a> framework to
simplify your unit and integration testing using <a shape="rect"
href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a>
and Camel's powerful <a shape="rect" href="mock.html">Mock</a> and <a
shape="rect" href="test.html">Test</a>
endpoints</li><li>From <strong>Camel 2.15</strong>: Cam
el supports Spring Boot using the <code><a shape="rect"
href="spring-boot.html">camel-spring-boot</a></code>
component.</li><li>From <strong>Camel 2.17.1</strong>: Camel supports
Spring Cache based Idempotent repository</li></ul><h2
id="Spring-UsingSpringtoconfiguretheCamelContext">Using Spring to configure the
CamelContext</h2><p>You can configure
a <strong><code>CamelContext</code></strong> inside
any <strong><code>spring.xml</code></strong> using the <a shape="rect"
class="external-link"
href="http://camel.apache.org/maven/current/camel-spring/apidocs/org/apache/camel/spring/CamelContextFactoryBean.html">CamelContextFactoryBean</a>.
This will automatically <a shape="rect" href="lifecycle.html">start</a> the <a
shape="rect" href="camelcontext.html">CamelContext</a> along with any
referenced <a shape="rect" href="routes.html">Routes</a> along any referenced
<a shape="rect" href="component.html">Component</a> and <a shape="rect"
href="endpoint.html">Endpoint</a>
instances.</p><ul><li>Adding Camel schema</li><li>Configure <a shape="rect"
href="routes.html">Routes</a> in two ways:<ul><li>Using Java Code</li><li>Using
Spring XML</li></ul></li></ul><h3 id="Spring-AddingCamelSchema">Adding Camel
Schema</h3><rich-text-body><p>For Camel 1.x you need to use the following
namespace:</p><plain-text-body>http://activemq.apache.org/camel/schema/spring
+</plain-text-body><p>with the following schema
location:</p><plain-text-body>http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+</plain-text-body></rich-text-body><p>You need to add Camel to the
<strong><code>schemaLocation</code></strong>
declaration</p><plain-text-body>http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
+</plain-text-body><p>So the XML file looks like this:</p><parameter
ac:name="">xml</parameter><plain-text-body><beans
xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
-]]></script>
-</div></div><h4
id="Spring-Usingcamel:Namespace">Using <code>camel:</code>
Namespace</h4><p>Or you can refer to the camel XSD in the XML
declaration:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[xmlns:camel="http://camel.apache.org/schema/spring"
-]]></script>
-</div></div><p>... so the declaration is:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:camel="http://camel.apache.org/schema/spring"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
-]]></script>
-</div></div>... and then use the <strong><code>camel:</code></strong>
namespace prefix, and you can omit the inline namespace declaration:<div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<camel:camelContext id="camel5">
- <camel:package>org.apache.camel.spring.example</camel:package>
-</camel:camelContext>
-]]></script>
-</div></div><h4 id="Spring-AdvancedConfigurationUsingSpring">Advanced
Configuration Using Spring</h4><p>See more details at <a shape="rect"
href="advanced-configuration-of-camelcontext-using-spring.html">Advanced
configuration of CamelContext using Spring</a></p><h3
id="Spring-UsingJavaCode">Using Java Code</h3><p>You can use Java Code to
define your <a shape="rect" href="routebuilder.html">RouteBuilder</a>
implementations. These can be defined as beans in spring and then referenced in
your camel context e.g.</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
- <camelContext id="camel5"
xmlns="http://camel.apache.org/schema/spring">
- <routeBuilder ref="myBuilder" />
- </camelContext>
-
- <bean id="myBuilder"
class="org.apache.camel.spring.example.test1.MyRouteBuilder"/>
-
-</beans>
-]]></script>
-</div></div><h4
id="Spring-Using<package>">Using <code><package></code></h4><p>Camel
also provides a powerful feature that allows for the automatic discovery and
initialization of routes in given packages. This is configured by adding tags
to the camel context in your spring context definition, specifying the packages
to be recursively searched for <a shape="rect"
href="routebuilder.html">RouteBuilder</a> implementations. To use this feature
in <strong><code>1.X</code></strong>, requires
a <strong><code><package></package></code></strong> tag
specifying a comma separated list of packages that should be searched
e.g.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <camelContext
xmlns="http://camel.apache.org/schema/spring">
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
+</plain-text-body><h4
id="Spring-Usingcamel:Namespace">Using <code>camel:</code>
Namespace</h4><p>Or you can refer to the camel XSD in the XML
declaration:</p><plain-text-body>xmlns:camel="http://camel.apache.org/schema/spring"
+</plain-text-body><p>... so the declaration
is:<plain-text-body>{snippet:id=xsdlocation|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}</plain-text-body>...
and then use the <strong><code>camel:</code></strong> namespace prefix,
and you can omit the inline namespace
declaration:<plain-text-body>{snippet:id=example5|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}</plain-text-body></p><h4
id="Spring-AdvancedConfigurationUsingSpring">Advanced Configuration Using
Spring</h4><p>See more details at <a shape="rect"
href="advanced-configuration-of-camelcontext-using-spring.html">Advanced
configuration of CamelContext using Spring</a></p><h3
id="Spring-UsingJavaCode">Using Java Code</h3><p>You can use Java Code to
define your <a shape="rect" href="routebuilder.html">RouteBuilder</a>
implementations. These can be defined as beans in spring and
then referenced in your camel context
e.g.<plain-text-body>{snippet:id=example5|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextRouteBuilderRef.xml}</plain-text-body></p><h4
id="Spring-Using<package>">Using <code><package></code></h4><p>Camel
also provides a powerful feature that allows for the automatic discovery and
initialization of routes in given packages. This is configured by adding tags
to the camel context in your spring context definition, specifying the packages
to be recursively searched for <a shape="rect"
href="routebuilder.html">RouteBuilder</a> implementations. To use this feature
in <strong><code>1.X</code></strong>, requires
a <strong><code><package></package></code></strong> tag
specifying a comma separated list of packages that should be searched
e.g.</p><parameter ac:name="">xml</parameter><plain-text-body>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<package>org.apache.camel.spring.config.scan.route</package>
</camelContext>
-]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-warning"><span class="aui-icon aui-icon-small
aui-iconfont-error confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Use caution when specifying the
package name as <strong><code>org.apache.camel</code></strong> or a sub package
of this. This causes Camel to search in its own packages for your routes which
could cause problems.</p></div></div><div class="confluence-information-macro
confluence-information-macro-information"><p class="title">Will ignore already
instantiated classes</p><span class="aui-icon aui-icon-small aui-iconfont-info
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The <strong><code><package></code></strong>
and <strong><code><packageScan></code></strong> will skip any
classes which has already been created by Spring etc. So if you define a route
builder as a spring bean tag the
n that class will be skipped. You can include those beans using
<strong><code><routeBuilder ref="theBeanId"/></code></strong> or the
<strong><code><contextScan></code></strong> feature.</p></div></div><h4
id="Spring-Using<packageScan>">Using <code><packageScan></code></h4><p>In
Camel 2.0 this has been extended to allow selective inclusion and exclusion of
discovered route classes using Ant like path matching. In spring this is
specified by adding a <strong><code><packageScan/></code></strong>
tag. The tag must contain one or
more <strong><code>package</code></strong> elements (similar to
<strong><code>1.x</code></strong>), and optionally one or
more <strong><code>includes</code></strong>
or <strong><code>excludes</code></strong> elements specifying patterns to
be applied to the fully qualified names of the discovered classes.
e.g.,</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl
">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <camelContext
xmlns="http://camel.apache.org/schema/spring">
+</plain-text-body><rich-text-body><p>Use caution when specifying the package
name as <strong><code>org.apache.camel</code></strong> or a sub package of
this. This causes Camel to search in its own packages for your routes which
could cause problems.</p></rich-text-body><parameter ac:name="title">Will
ignore already instantiated
classes</parameter><rich-text-body><p>The <strong><code><package></code></strong>
and <strong><code><packageScan></code></strong> will skip any
classes which has already been created by Spring etc. So if you define a route
builder as a spring bean tag then that class will be skipped. You can include
those beans using <strong><code><routeBuilder
ref="theBeanId"/></code></strong> or the
<strong><code><contextScan></code></strong>
feature.</p></rich-text-body><h4
id="Spring-Using<packageScan>">Using <code><packageScan></code></h4><p>In
Camel 2.0 this has been extended to allow selective inclusion and exclusion o
f discovered route classes using Ant like path matching. In spring this is
specified by adding a <strong><code><packageScan/></code></strong>
tag. The tag must contain one or
more <strong><code>package</code></strong> elements (similar to
<strong><code>1.x</code></strong>), and optionally one or
more <strong><code>includes</code></strong>
or <strong><code>excludes</code></strong> elements specifying patterns to
be applied to the fully qualified names of the discovered classes.
e.g.,</p><parameter ac:name="">xml</parameter><plain-text-body>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<packageScan>
<package>org.example.routes</package>
<excludes>**.*Excluded*</excludes>
<includes>**.*</includes>
</packageScan>
</camelContext>
-]]></script>
-</div></div><p>Exclude patterns are applied before the include patterns. If no
include or exclude patterns are defined then all the Route classes discovered
in the packages will be returned.</p><p>In the above example, camel will scan
all the <strong><code>org.example.routes</code></strong> package and any
subpackages for <strong><code>RouteBuilder</code></strong> classes. Say
the scan finds two <strong><code>RouteBuilders</code></strong>, one
in <strong><code>org.example.routes</code></strong>
called <strong><code>MyRoute</code></strong> and
another <strong><code>MyExcludedRoute</code></strong> in a subpackage
<strong><code>excluded</code></strong>. The fully qualified names of each of
the classes are extracted
(<strong><code>org.example.routes.MyRoute</code></strong>, <strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong>
) and the include and exclude patterns are applied.</p><p>The exclude
pattern <strong><code>**.*Excluded*</
code></strong> is going to match the FQCN
<strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong> and
veto camel from initializing it.</p><p>Under the covers, this is using Spring's
<a shape="rect" class="external-link"
href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html"
rel="nofollow">AntPatternMatcher</a> implementation, which matches as
follows</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[? matches one character
+</plain-text-body><p>Exclude patterns are applied before the include patterns.
If no include or exclude patterns are defined then all the Route classes
discovered in the packages will be returned.</p><p>In the above example, camel
will scan all the <strong><code>org.example.routes</code></strong> package
and any subpackages for <strong><code>RouteBuilder</code></strong>
classes. Say the scan finds two <strong><code>RouteBuilders</code></strong>,
one in <strong><code>org.example.routes</code></strong>
called <strong><code>MyRoute</code></strong> and
another <strong><code>MyExcludedRoute</code></strong> in a subpackage
<strong><code>excluded</code></strong>. The fully qualified names of each of
the classes are extracted
(<strong><code>org.example.routes.MyRoute</code></strong>, <strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong>
) and the include and exclude patterns are applied.</p><p>The exclude
pattern <strong><code>**.*Exclu
ded*</code></strong> is going to match the FQCN
<strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong> and
veto camel from initializing it.</p><p>Under the covers, this is using Spring's
<a shape="rect" class="external-link"
href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html"
rel="nofollow">AntPatternMatcher</a> implementation, which matches as
follows</p><plain-text-body>? matches one character
* matches zero or more characters
** matches zero or more segments of a fully qualified name
-]]></script>
-</div></div><p>For example:</p><p><strong><code>**.*Excluded*</code></strong>
would match
<strong><code>org.simple.Excluded</code></strong>, <strong><code>org.apache.camel.SomeExcludedRoute</code></strong>
or
<strong><code>org.example.RouteWhichIsExcluded</code></strong>.</p><p><strong><code>**.??cluded*</code></strong>
would match
<strong><code>org.simple.IncludedRoute</code></strong>, <strong><code>org.simple.Excluded</code></strong>
but <em>not</em> match
<strong><code>org.simple.PrecludedRoute</code></strong>.</p><h4
id="Spring-UsingcontextScan">Using <code>contextScan</code></h4><p><strong>Available
as of Camel 2.4</strong></p><p>You can allow Camel to scan the container
context, e.g. the Spring <strong><code>ApplicationContext</code></strong> for
route builder instances. This allow you to use the Spring
<strong><code><component-scan></code></strong> feature and have Camel
pickup any <strong><code>RouteBuilder</code></strong> instances which was
create
d by Spring in its scan process.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<!-- enable Spring @Component scan -->
-<context:component-scan
base-package="org.apache.camel.spring.issues.contextscan"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <!-- and then let Camel use those @Component scanned route builders
-->
- <contextScan/>
-</camelContext>
-]]></script>
-</div></div>This allows you to just annotate your routes using the Spring
<strong><code>@Component</code></strong> and have those routes included by
Camel:<div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[@Component
+</plain-text-body><p>For
example:</p><p><strong><code>**.*Excluded*</code></strong> would match
<strong><code>org.simple.Excluded</code></strong>, <strong><code>org.apache.camel.SomeExcludedRoute</code></strong>
or
<strong><code>org.example.RouteWhichIsExcluded</code></strong>.</p><p><strong><code>**.??cluded*</code></strong>
would match
<strong><code>org.simple.IncludedRoute</code></strong>, <strong><code>org.simple.Excluded</code></strong>
but <em>not</em> match
<strong><code>org.simple.PrecludedRoute</code></strong>.</p><h4
id="Spring-UsingcontextScan">Using <code>contextScan</code></h4><p><strong>Available
as of Camel 2.4</strong></p><p>You can allow Camel to scan the container
context, e.g. the Spring <strong><code>ApplicationContext</code></strong> for
route builder instances. This allow you to use the Spring
<strong><code><component-scan></code></strong> feature and have Camel
pickup any <strong><code>RouteBuilder</code></strong> instances which was
created by Spring in its scan
process.<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/contextscan/SpringRouteIsComponentAnnotatedTest.xml}</plain-text-body>This
allows you to just annotate your routes using the Spring
<strong><code>@Component</code></strong> and have those routes included by
Camel:</p><plain-text-body>@Component
public class MyRoute extends SpringRouteBuilder {
@Override
public void configure() throws Exception {
- from("direct:start")
- .to("mock:result");
+ from("direct:start")
+ .to("mock:result");
}
}
-]]></script>
-</div></div><p>You can also use the ANT style for inclusion and exclusion, as
mentioned above in the <strong><code><packageScan></code></strong>
documentation.</p><p></p><div class="error"><span class="error">Unable to
render {include}</span> The included page could not be found.</div><h4
id="Spring-TestTimeExclusion.">Test Time Exclusion.</h4><p>At test time it is
often desirable to be able to selectively exclude matching routes from being
initialized that are not applicable or useful to the test scenario. For
instance you might a spring context
file <strong><code>routes-context.xml</code></strong> and three Route
builders <strong><code>RouteA</code>, </strong><code>RouteB</code>
and <strong><code>RouteC</code></strong> in
the <strong><code>org.example.routes</code></strong> package.
The <strong><code>packageScan</code></strong> definition would discover
all three of these routes and initialize
them.</p><p>Say <strong><code>RouteC</code></strong>
is not applicable to our test scenario and generates a lot of noise during
test. It would be nice to be able to exclude this route from this specific
test. The <strong><code>SpringTestSupport</code></strong> class has been
modified to allow this. It provides two methods
(<strong><code>excludedRoute</code></strong> and
<strong><code>excludedRoutes</code></strong>) that may be overridden to exclude
a single class or an array of classes.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[public class RouteAandRouteBOnlyTest extends
SpringTestSupport {
+</plain-text-body><p>You can also use the ANT style for inclusion and
exclusion, as mentioned above in the
<strong><code><packageScan></code></strong>
documentation.</p><p><parameter ac:name=""><a shape="rect" class="unresolved"
href="#">how do i import routes from other xml files</a></parameter></p><h4
id="Spring-TestTimeExclusion.">Test Time Exclusion.</h4><p>At test time it is
often desirable to be able to selectively exclude matching routes from being
initialized that are not applicable or useful to the test scenario. For
instance you might a spring context
file <strong><code>routes-context.xml</code></strong> and three Route
builders <strong><code>RouteA</code>, </strong><code>RouteB</code>
and <strong><code>RouteC</code></strong> in
the <strong><code>org.example.routes</code></strong> package.
The <strong><code>packageScan</code></strong> definition would discover
all three of these routes and initialize
them.</p><p>Say <strong><code>RouteC<
/code></strong> is not applicable to our test scenario and generates a lot of
noise during test. It would be nice to be able to exclude this route from this
specific test. The <strong><code>SpringTestSupport</code></strong> class
has been modified to allow this. It provides two methods
(<strong><code>excludedRoute</code></strong> and
<strong><code>excludedRoutes</code></strong>) that may be overridden to exclude
a single class or an array of classes.</p><parameter
ac:name="">java</parameter><plain-text-body>public class
RouteAandRouteBOnlyTest extends SpringTestSupport {
@Override
protected Class excludeRoute() {
return RouteC.class;
}
}
-]]></script>
-</div></div><p>In order to hook into
the <strong><code>camelContext</code></strong> initialization by spring to
exclude the <strong><code>MyExcludedRouteBuilder.class</code></strong> we
need to intercept the spring context creation. When
overriding <strong><code>createApplicationContext</code></strong> to
create the spring context, we call
the <strong><code>getRouteExcludingApplicationContext()</code></strong>
method to provide a special parent spring context that takes care of the
exclusion.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[@Override
+</plain-text-body><p>In order to hook into
the <strong><code>camelContext</code></strong> initialization by spring to
exclude the <strong><code>MyExcludedRouteBuilder.class</code></strong> we
need to intercept the spring context creation. When
overriding <strong><code>createApplicationContext</code></strong> to
create the spring context, we call
the <strong><code>getRouteExcludingApplicationContext()</code></strong>
method to provide a special parent spring context that takes care of the
exclusion.</p><parameter ac:name="">java</parameter><plain-text-body>@Override
protected AbstractXmlApplicationContext createApplicationContext() {
- return new ClassPathXmlApplicationContext(new String[]
{"routes-context.xml"}, getRouteExcludingApplicationContext());
+ return new ClassPathXmlApplicationContext(new String[]
{"routes-context.xml"}, getRouteExcludingApplicationContext());
}
-]]></script>
-</div></div><p><strong><code>RouteC</code></strong> will now be excluded from
initialization. Similarly, in another test that is testing only
<strong><code>RouteC</code></strong>, we could
exclude <strong><code>RouteB</code></strong>
and <strong><code>RouteA</code></strong> by overriding:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[@Override
+</plain-text-body><p><strong><code>RouteC</code></strong> will now be excluded
from initialization. Similarly, in another test that is testing only
<strong><code>RouteC</code></strong>, we could
exclude <strong><code>RouteB</code></strong>
and <strong><code>RouteA</code></strong> by
overriding:</p><plain-text-body>@Override
protected Class[] excludeRoutes() {
return new Class[]{RouteA.class, RouteB.class};
}
-]]></script>
-</div></div><h3 id="Spring-UsingSpringXML">Using Spring XML</h3><p>You can use
Spring 2.0 XML configuration to specify your <a shape="rect"
href="xml-configuration.html">Xml Configuration</a> for <a shape="rect"
href="routes.html">Routes</a> such as in the following <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactory.xml">example</a>.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<camelContext id="camel-A"
xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="seda:start"/>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-]]></script>
-</div></div><h2 id="Spring-ConfiguringComponentsandEndpoints">Configuring
Components and Endpoints</h2><p>You can configure your <a shape="rect"
href="component.html">Component</a> or <a shape="rect"
href="endpoint.html">Endpoint</a> instances in your <a shape="rect"
href="spring.html">Spring</a> XML as follows in <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml">this
example</a>.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
- <jmxAgent id="agent" disabled="true"/>
-</camelContext>
-
-<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
- <property name="connectionFactory">
- <bean
class="org.apache.activemq.ActiveMQConnectionFactory">
- <property name="brokerURL"
value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
- </bean>
- </property>
-</bean>
-]]></script>
-</div></div>Which allows you to configure a component using some name
(<strong><code>activemq</code></strong> in the above example), then you can
refer to the component using
<strong><code>activemq:[queue:|topic:]destinationName</code></strong>. This
works by the <strong><code>SpringCamelContext</code></strong> lazily
fetching components from the spring context for the scheme name you use for <a
shape="rect" href="endpoint.html">Endpoint</a> <a shape="rect"
href="uris.html">URIs</a>.<p>For more detail see <a shape="rect"
href="how-do-i-configure-endpoints.html">Configuring Endpoints and
Components</a>.</p><h2 id="Spring-SpringCacheIdempotentRepository">Spring Cache
Idempotent Repository</h2><p>Available as of <strong>Camel
2.17.1</strong></p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<bean id="repo"
class="org.apache.camel.spring.processor.idempotent.SpringCacheIdempotentRepository">
+</plain-text-body><h3 id="Spring-UsingSpringXML">Using Spring XML</h3><p>You
can use Spring 2.0 XML configuration to specify your <a shape="rect"
href="xml-configuration.html">Xml Configuration</a> for <a shape="rect"
href="routes.html">Routes</a> such as in the following <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactory.xml">example</a>.<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactory.xml}</plain-text-body></p><h2
id="Spring-ConfiguringComponentsandEndpoints">Configuring Components and
Endpoints</h2><p>You can configure your <a shape="rect"
href="component.html">Component</a> or <a shape="rect"
href="endpoint.html">Endpoint</a> instances in your <a shape="rect"
href="spring.html">Spring</a> XML as follows in <a shape="rect" class="extern
al-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml">this
example</a>.<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml}</plain-text-body>Which
allows you to configure a component using some name
(<strong><code>activemq</code></strong> in the above example), then you can
refer to the component using
<strong><code>activemq:[queue:|topic:]destinationName</code></strong>. This
works by the <strong><code>SpringCamelContext</code></strong> lazily
fetching components from the spring context for the scheme name you use for <a
shape="rect" href="endpoint.html">Endpoint</a> <a shape="rect"
href="uris.html">URIs</a>.</p><p>For more detail see <a shape="rect"
href="how-do-i-configure-endpoints.html">Configuring Endpoints and
Components</a>.</p><h2 id="Spring-SpringCacheIdempotentRepo
sitory">Spring Cache Idempotent Repository</h2><p>Available as of
<strong>Camel 2.17.1</strong></p><parameter
ac:name="language">xml</parameter><plain-text-body><bean id="repo"
class="org.apache.camel.spring.processor.idempotent.SpringCacheIdempotentRepository">
<constructor-arg>
- <bean
class="org.springframework.cache.guava.GuavaCacheManager"/>
+ <bean class="org.springframework.cache.guava.GuavaCacheManager"/>
</constructor-arg>
- <constructor-arg value="idempotent"/>
+ <constructor-arg value="idempotent"/>
</bean>
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route id="idempotent-cache">
- <from uri="direct:start" />
- <idempotentConsumer messageIdRepositoryRef="repo"
skipDuplicate="true">
+<camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route id="idempotent-cache">
+ <from uri="direct:start" />
+ <idempotentConsumer messageIdRepositoryRef="repo"
skipDuplicate="true">
<header>MessageId</header>
- <to
uri="log:org.apache.camel.spring.processor.idempotent?level=INFO&amp;showAll=true&amp;multiline=true"
/>
- <to uri="mock:result"/>
+ <to
uri="log:org.apache.camel.spring.processor.idempotent?level=INFO&amp;showAll=true&amp;multiline=true"
/>
+ <to uri="mock:result"/>
</idempotentConsumer>
</route>
-</camelContext>]]></script>
-</div></div><p> </p><p> </p><h3
id="Spring-CamelContextAware">CamelContextAware</h3><p>If you want to be
injected with the <a shape="rect" href="camelcontext.html">CamelContext</a> in
your POJO just implement the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContextAware.html">CamelContextAware
interface</a>; then when Spring creates your POJO
the <strong><code>CamelContext</code></strong> will be injected into your
POJO. Also see the <a shape="rect" href="bean-integration.html">Bean
Integration</a> for further injections.</p><h2
id="Spring-IntegrationTesting">Integration Testing</h2><p>To avoid a hung route
when testing using Spring Transactions see the note about Spring Integration
Testing under <a shape="rect"
href="transactional-client.html">Transactional Client</a>.</p><h3
id="Spring-Seealso">See also</h3><ul><li><a shape="rect"
href="tutorial-jmsremoting.html">Spring JMS Tutorial</
a></li><li><a shape="rect"
href="creating-a-new-spring-based-camel-route.html">Creating a new Spring based
Camel Route</a></li><li><a shape="rect" href="spring-example.html">Spring
example</a></li><li><a shape="rect" href="xml-reference.html">Xml
Reference</a></li><li><a shape="rect"
href="advanced-configuration-of-camelcontext-using-spring.html">Advanced
configuration of CamelContext using Spring</a></li><li><a shape="rect"
href="how-do-i-import-routes-from-other-xml-files.html">How Do I Import Routes
From Other XML Files?</a></li></ul></div>
+</camelContext></plain-text-body><p> </p><p> </p><h3
id="Spring-CamelContextAware">CamelContextAware</h3><p>If you want to be
injected with the <a shape="rect" href="camelcontext.html">CamelContext</a> in
your POJO just implement the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContextAware.html">CamelContextAware
interface</a>; then when Spring creates your POJO
the <strong><code>CamelContext</code></strong> will be injected into your
POJO. Also see the <a shape="rect" href="bean-integration.html">Bean
Integration</a> for further injections.</p><h2
id="Spring-IntegrationTesting">Integration Testing</h2><p>To avoid a hung route
when testing using Spring Transactions see the note about Spring Integration
Testing under <a shape="rect"
href="transactional-client.html">Transactional Client</a>.</p><h3
id="Spring-Seealso">See also</h3><ul><li><a shape="rect"
href="tutorial-jmsremoting.
html">Spring JMS Tutorial</a></li><li><a shape="rect"
href="creating-a-new-spring-based-camel-route.html">Creating a new Spring based
Camel Route</a></li><li><a shape="rect" href="spring-example.html">Spring
example</a></li><li><a shape="rect" href="xml-reference.html">Xml
Reference</a></li><li><a shape="rect"
href="advanced-configuration-of-camelcontext-using-spring.html">Advanced
configuration of CamelContext using Spring</a></li><li><a shape="rect"
href="how-do-i-import-routes-from-other-xml-files.html">How Do I Import Routes
From Other XML Files?</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">