Modified: websites/production/camel/content/how-do-i-configure-endpoints.html
==============================================================================
--- websites/production/camel/content/how-do-i-configure-endpoints.html
(original)
+++ websites/production/camel/content/how-do-i-configure-endpoints.html Fri Aug
25 08:22:01 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: How Do I Configure Endpoints?
@@ -86,119 +75,73 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="HowDoIConfigureEndpoints?-HowDoIConfigureEndpoints?">How Do I Configure
Endpoints?</h2><p>There are a few different approaches to configuring
components and endpoints.</p><h3 id="HowDoIConfigureEndpoints?-UsingJava">Using
Java</h3><p>You can explicitly configure a <a shape="rect"
href="component.html">Component</a> using Java code as shown in this <a
shape="rect" href="walk-through-an-example.html">example</a></p><p>Or you can
explicitly get hold of an <a shape="rect" href="endpoint.html">Endpoint</a> and
configure it using Java code as shown in the <a shape="rect"
href="mock.html">Mock endpoint examples</a>.</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[SomeEndpoint endpoint =
camelContext.getEndpoint("someURI", SomeEndpoint.class);
-endpoint.setSomething("aValue");]]></script>
-</div></div><h3 id="HowDoIConfigureEndpoints?-UsingCDI">Using CDI</h3><p>You
can use <a shape="rect" href="cdi.html">CDI</a> as dependency injection
framework to configure your <a shape="rect"
href="component.html">Component</a> or <a shape="rect"
href="endpoint.html">Endpoint</a> instances.</p><p>For example, to
configure the SJMS component, you can declare a producer method in a CDI
bean:</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[class MyCdiComponent {
+<div class="wiki-content maincontent"><h2
id="HowDoIConfigureEndpoints?-HowDoIConfigureEndpoints?">How Do I Configure
Endpoints?</h2><p>There are a few different approaches to configuring
components and endpoints.</p><h3 id="HowDoIConfigureEndpoints?-UsingJava">Using
Java</h3><p>You can explicitly configure a <a shape="rect"
href="component.html">Component</a> using Java code as shown in this <a
shape="rect" href="walk-through-an-example.html">example</a></p><p>Or you can
explicitly get hold of an <a shape="rect" href="endpoint.html">Endpoint</a> and
configure it using Java code as shown in the <a shape="rect"
href="mock.html">Mock endpoint examples</a>.</p><plain-text-body>SomeEndpoint
endpoint = camelContext.getEndpoint("someURI", SomeEndpoint.class);
+endpoint.setSomething("aValue");</plain-text-body><h3
id="HowDoIConfigureEndpoints?-UsingCDI">Using CDI</h3><p>You can use <a
shape="rect" href="cdi.html">CDI</a> as dependency injection framework to
configure your <a shape="rect" href="component.html">Component</a> or
<a shape="rect" href="endpoint.html">Endpoint</a> instances.</p><p>For
example, to configure the SJMS component, you can declare a producer
method in a CDI bean:</p><parameter
ac:name="language">java</parameter><plain-text-body>class MyCdiComponent {
- @PropertyInject("jms.maxConnections")
+ @PropertyInject("jms.maxConnections")
int maxConnections;
@Produces
- @Named("sjms")
+ @Named("sjms")
@ApplicationScoped
SjmsComponent sjms() {
SjmsComponent component = new SjmsComponent();
- component.setConnectionFactory(new
ActiveMQConnectionFactory("vm://broker?broker.persistent=false"));
+ component.setConnectionFactory(new
ActiveMQConnectionFactory("vm://broker?broker.persistent=false"));
component.setConnectionCount(maxConnections);
return component;
}
-}]]></script>
-</div></div><p>Then, the component is lazily looked-up by Camel CDI whenever
it is referenced, e.g., from the Camel Java DSL:</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[class MyCdiRoute extends RouteBuilder {
+}</plain-text-body><p>Then, the component is lazily looked-up by Camel CDI
whenever it is referenced, e.g., from the Camel Java DSL:</p><parameter
ac:name="language">java</parameter><plain-text-body>class MyCdiRoute extends
RouteBuilder {
@Override
public void configure() {
- from("sjms:sample.queue")
- .log("Received message [${body}]");
+ from("sjms:sample.queue")
+ .log("Received message [${body}]");
}
-}]]></script>
-</div></div><p>Besides, endpoints of that component can be injected in any CDI
beans, e.g.,</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[class MyCdiBean {
+}</plain-text-body><p>Besides, endpoints of that component can be injected in
any CDI beans, e.g.,</p><parameter
ac:name="language">java</parameter><plain-text-body>class MyCdiBean {
@Inject
- @Uri("sjms:sample.queue")
+ @Uri("sjms:sample.queue")
Endpoint endpoint;
-}]]></script>
-</div></div><h3 id="HowDoIConfigureEndpoints?-UsingGuice">Using
Guice</h3><p>You can also use <a shape="rect" href="guice.html">Guice</a> as
the dependency injection framework. For example see the <a shape="rect"
href="guice-jms-example.html">Guice JMS Example</a>.</p><h3
id="HowDoIConfigureEndpoints?-UsingSpringXML">Using Spring XML</h3><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.</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
(activemq 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><h3
id="HowDoIConfigureEndpoints?-UsingEndpointURIs">Using Endpoint
URIs</h3><p>Another approach is to use the URI syntax. The URI syntax supports
the query notation. So for example with the <a shape="rect"
href="mail.html">Mail</a> component you can configure the password property via
the URI</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[pop3://host:port?password=foo
-]]></script>
-</div></div><h4
id="HowDoIConfigureEndpoints?-ReferencingBeansfromEndpointURIs">Referencing
Beans from Endpoint URIs</h4><p><strong>From Camel 2.0:</strong></p><p>When
configuring endpoints using URI syntax you can now refer to beans in the <a
shape="rect" href="registry.html">Registry</a> using
the <strong><code>#</code></strong> notation.<br clear="none"> If the
parameter value starts with a <code>#</code> sign then Camel will lookup in the
<a shape="rect" href="registry.html">Registry</a> for a bean of the given type.
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[file://inbox?sorter=#mySpecialFileSorter
-]]></script>
-</div></div><p>Will lookup a bean with the id
<strong><code>mySpecialFileSorter</code></strong> in the <a shape="rect"
href="registry.html">Registry</a>.</p><h4
id="HowDoIConfigureEndpoints?-ConfiguringParameterValuesUsingRawValues,e.g.,suchaspasswords">Configuring
Parameter Values Using Raw Values, e.g., such as passwords</h4><p><strong>From
Camel 2.11:</strong></p><p>When configuring endpoint options using URI syntax,
then the values is by default URI encoded. This can be a problem if you want to
configure passwords and just use the value <em>as is</em> without any encoding.
For example you may have a plus sign in the password, which would be decimal
encoded by default.</p><p>From <strong>Camel 2.11</strong>: we made this easier
as you can denote a parameter value to be <strong>raw</strong> using the
following syntax <strong><code>RAW(value)</code></strong> e.g., the value
starts with <strong><code>RAW(</code></strong> and then ends with the
parenthesis <strong><code>)</code></str
ong>. Here is a little 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[.to("ftp:[email protected]?password=RAW(se+re?t&23)&binary=true"
-]]></script>
-</div></div><p>In the above example, we have declare the password value as
raw, and the actual password would be as typed, e.g.,
<strong><code>se+re?t&23</code></strong>.</p><h4
id="HowDoIConfigureEndpoints?-UsingPropertyPlaceholders">Using Property
Placeholders</h4><p>Camel have extensive support for using property
placeholders, which you can read more <a shape="rect"
href="using-propertyplaceholder.html">about here</a>. For example in the ftp
example above we can externalize the password to
a <strong><code>.properties</code></strong> file.</p><p>For example
configuring the property placeholder when using a <a shape="rect"
href="dsl.html">XML DSL</a>, where we declare the location of the .properties
file. Though we can also define this in Java code. See the <a shape="rect"
href="using-propertyplaceholder.html">documentation</a> for more
details.</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 ...>
- <propertyPlaceholder id="properties"
location="myftp.properties"/>
+}</plain-text-body><h3 id="HowDoIConfigureEndpoints?-UsingGuice">Using
Guice</h3><p>You can also use <a shape="rect" href="guice.html">Guice</a> as
the dependency injection framework. For example see the <a shape="rect"
href="guice-jms-example.html">Guice JMS Example</a>.</p><h3
id="HowDoIConfigureEndpoints?-UsingSpringXML">Using Spring XML</h3><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.<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 (activemq 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><h3
>id="HowDoIConfigureEndpoints?-UsingEndpointURIs">Using Endpoint
>URIs</h3><p>Another approach is to use the URI syntax. The URI syntax
>supports the query notation. So for example with the <a shape="rect"
>href="mail.html">Mail</a> component you can configure the password property
>via the URI</p><plain-text-body>pop3://host:port?password=foo
+</plain-text-body><h4
id="HowDoIConfigureEndpoints?-ReferencingBeansfromEndpointURIs">Referencing
Beans from Endpoint URIs</h4><p><strong>From Camel 2.0:</strong></p><p>When
configuring endpoints using URI syntax you can now refer to beans in the <a
shape="rect" href="registry.html">Registry</a> using
the <strong><code>#</code></strong> notation.<br clear="none"> If the
parameter value starts with a <code>#</code> sign then Camel will lookup in the
<a shape="rect" href="registry.html">Registry</a> for a bean of the given type.
For instance:</p><plain-text-body>file://inbox?sorter=#mySpecialFileSorter
+</plain-text-body><p>Will lookup a bean with the id
<strong><code>mySpecialFileSorter</code></strong> in the <a shape="rect"
href="registry.html">Registry</a>.</p><h4
id="HowDoIConfigureEndpoints?-ConfiguringParameterValuesUsingRawValues,e.g.,suchaspasswords">Configuring
Parameter Values Using Raw Values, e.g., such as passwords</h4><p><strong>From
Camel 2.11:</strong></p><p>When configuring endpoint options using URI syntax,
then the values is by default URI encoded. This can be a problem if you want to
configure passwords and just use the value <em>as is</em> without any encoding.
For example you may have a plus sign in the password, which would be decimal
encoded by default.</p><p>From <strong>Camel 2.11</strong>: we made this easier
as you can denote a parameter value to be <strong>raw</strong> using the
following syntax <strong><code>RAW(value)</code></strong> e.g., the value
starts with <strong><code>RAW(</code></strong> and then ends with the
parenthesis <strong><code>)</code
></strong>. Here is a little
>example:</p><plain-text-body>.to("ftp:[email protected]?password=RAW(se+re?t&23)&binary=true"
+</plain-text-body><p>In the above example, we have declare the password value
as raw, and the actual password would be as typed, e.g.,
<strong><code>se+re?t&23</code></strong>.</p><h4
id="HowDoIConfigureEndpoints?-UsingPropertyPlaceholders">Using Property
Placeholders</h4><p>Camel have extensive support for using property
placeholders, which you can read more <a shape="rect"
href="using-propertyplaceholder.html">about here</a>. For example in the ftp
example above we can externalize the password to
a <strong><code>.properties</code></strong> file.</p><p>For example
configuring the property placeholder when using a <a shape="rect"
href="dsl.html">XML DSL</a>, where we declare the location of the .properties
file. Though we can also define this in Java code. See the <a shape="rect"
href="using-propertyplaceholder.html">documentation</a> for more
details.</p><parameter
ac:name="language">xml</parameter><plain-text-body><camelContext ...>
+ <propertyPlaceholder id="properties" location="myftp.properties"/>
...
</camelContext>
-]]></script>
-</div></div><p>And the Camel route now refers to the placeholder using the
<strong>{{</strong> key <strong>}}</strong> notation:</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[.to("ftp:[email protected]?password={{myFtpPassword}}&binary=true"
-]]></script>
-</div></div><p>And have a <strong><code>myftp.properties</code></strong>
file with password. Notice we still define the RAW(value) style to ensure the
password is used <em>as is</em></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[myFtpPassword=RAW(se+re?t&23)
-]]></script>
-</div></div><p>We could still have used the RAW(value) in the Camel route
instead:</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[.to("ftp:[email protected]?password=RAW({{myFtpPassword}})&binary=true"
-]]></script>
-</div></div><p>And then we would need to remove the RAW from the properties
file:</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[myFtpPassword=se+re?t&23
-]]></script>
-</div></div><p>To understand more about property placeholders, read the <a
shape="rect" href="using-propertyplaceholder.html">documentation</a>.</p><h3
id="HowDoIConfigureEndpoints?-ConfiguringURIsusingEndpointwithBeanPropertyStyle">Configuring
URIs using Endpoint with Bean Property Style</h3><p><strong>Available as of
Camel 2.15</strong></p><div><p>Sometimes configuring endpoint uris may have
many options, and therefore the URI can become long. In Java DSL you can break
the URIs into new lines as its just Java code, e.g., just concat the String.
When using XML DSL then the URI is an attribute, e.g., <strong><code><from
uri="bla bla"/></code></strong>. From <strong>Camel 2.15</strong>: you can
configure the endpoint separately, and from the routes refer to the endpoints
using their shorthand IDs. </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 ...>
-Â
- <endpoint id="foo" uri="ftp://foo@myserver">
- <property name="password" value="secret"/>
- <property name="recursive" value="true"/>
- <property name="ftpClient.dataTimeout"
value="30000"/>
- <property name="ftpClient.serverLanguageCode"
value="fr"/>Â
+</plain-text-body><p>And the Camel route now refers to the placeholder using
the <strong>{{</strong> key <strong>}}</strong> notation:</p><parameter
ac:name="language">java</parameter><plain-text-body>.to("ftp:[email protected]?password={{myFtpPassword}}&binary=true"
+</plain-text-body><p>And have
a <strong><code>myftp.properties</code></strong> file with password.
Notice we still define the RAW(value) style to ensure the password is used
<em>as is</em></p><plain-text-body>myFtpPassword=RAW(se+re?t&23)
+</plain-text-body><p>We could still have used the RAW(value) in the Camel
route instead:</p><parameter
ac:name="language">java</parameter><plain-text-body>.to("ftp:[email protected]?password=RAW({{myFtpPassword}})&binary=true"
+</plain-text-body><p>And then we would need to remove the RAW from the
properties file:</p><plain-text-body>myFtpPassword=se+re?t&23
+</plain-text-body><p>To understand more about property placeholders, read the
<a shape="rect" href="using-propertyplaceholder.html">documentation</a>.</p><h3
id="HowDoIConfigureEndpoints?-ConfiguringURIsusingEndpointwithBeanPropertyStyle">Configuring
URIs using Endpoint with Bean Property Style</h3><p><strong>Available as of
Camel 2.15</strong></p><div><p>Sometimes configuring endpoint uris may have
many options, and therefore the URI can become long. In Java DSL you can break
the URIs into new lines as its just Java code, e.g., just concat the String.
When using XML DSL then the URI is an attribute, e.g., <strong><code><from
uri="bla bla"/></code></strong>. From <strong>Camel 2.15</strong>: you can
configure the endpoint separately, and from the routes refer to the endpoints
using their shorthand IDs. </p><parameter
ac:name="language">xml</parameter><plain-text-body><camelContext ...>
+ 
+ <endpoint id="foo" uri="ftp://foo@myserver">
+ <property name="password" value="secret"/>
+ <property name="recursive" value="true"/>
+ <property name="ftpClient.dataTimeout" value="30000"/>
+ <property name="ftpClient.serverLanguageCode" value="fr"/> 
</endpoint>
-Â
+ 
<route>
- <from uri="ref:foo"/>
+ <from uri="ref:foo"/>
...
</route>
-</camelContext>]]></script>
-</div></div><p> </p><p>In the example above, the endpoint with id foo, is
defined using <strong><code><endpoint></code></strong> which under
the covers assembles this as an URI, with all the options, as if you have
defined all the options directly in the URI. You can still configure some
options in the URI, and then
use <strong><code><property></code></strong> style for additional
options, or to override options from the URI, such as:</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[<endpoint id="foo"
uri="ftp://foo@myserver?recursive=true">
- <property name="password" value="secret"/>
- <property name="ftpClient.dataTimeout"
value="30000"/>
- <property name="ftpClient.serverLanguageCode"
value="fr"/>
-</endpoint>]]></script>
-</div></div><p> </p></div><h3
id="HowDoIConfigureEndpoints?-ConfiguringLongURIsUsingNewLines">Configuring
Long URIs Using New Lines</h3><p><strong>Available as of Camel
2.15</strong></p><p>Sometimes configuring endpoint URIs may have many options,
and therefore the URI can become long. In Java DSL you can break the URIs into
new lines as its just Java code, e.g., just concat the String. When using XML
DSL then the URI is an attribute, e.g., <strong><code><from uri="bla
bla"/></code></strong>. From <strong>Camel 2.15</strong>: you can break the
URI attribute using new line, such as shown below:</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[<route>
- <from uri="ftp://foo@myserver?password=secret&amp;
+</camelContext></plain-text-body><p> </p><p>In the example above,
the endpoint with id foo, is defined
using <strong><code><endpoint></code></strong> which under the
covers assembles this as an URI, with all the options, as if you have defined
all the options directly in the URI. You can still configure some options in
the URI, and then use <strong><code><property></code></strong> style
for additional options, or to override options from the URI, such
as:</p><parameter
ac:name="language">xml</parameter><plain-text-body><endpoint id="foo"
uri="ftp://foo@myserver?recursive=true">
+ <property name="password" value="secret"/>
+ <property name="ftpClient.dataTimeout" value="30000"/>
+ <property name="ftpClient.serverLanguageCode" value="fr"/>
+</endpoint></plain-text-body><p> </p></div><h3
id="HowDoIConfigureEndpoints?-ConfiguringLongURIsUsingNewLines">Configuring
Long URIs Using New Lines</h3><p><strong>Available as of Camel
2.15</strong></p><p>Sometimes configuring endpoint URIs may have many options,
and therefore the URI can become long. In Java DSL you can break the URIs into
new lines as its just Java code, e.g., just concat the String. When using XML
DSL then the URI is an attribute, e.g., <strong><code><from uri="bla
bla"/></code></strong>. From <strong>Camel 2.15</strong>: you can break the
URI attribute using new line, such as shown below:</p><parameter
ac:name="language">xml</parameter><plain-text-body><route>
+ <from uri="ftp://foo@myserver?password=secret&amp;
recursive=true&amp;
ftpClient.dataTimeout=30000&amp;
- ftpClientConfig.serverLanguageCode=fr"/>
- <to uri="bean:doSomething"/>
-</route>]]></script>
-</div></div><p>Notice that it still requires to use
escape <strong><code>&</code></strong>
as <strong><code>&amp;</code></strong> in XML. Also you can have
multiple options in one line, e.g., this is the same:</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[<route>
- <from uri="ftp://foo@myserver?password=secret&amp;
+ ftpClientConfig.serverLanguageCode=fr"/>
+ <to uri="bean:doSomething"/>
+</route></plain-text-body><p>Notice that it still requires to use
escape <strong><code>&</code></strong>
as <strong><code>&amp;</code></strong> in XML. Also you can have
multiple options in one line, e.g., this is the same:</p><parameter
ac:name="language">xml</parameter><plain-text-body><route>
+ <from uri="ftp://foo@myserver?password=secret&amp;
recursive=true&amp;ftpClient.dataTimeout=30000&amp;
- ftpClientConfig.serverLanguageCode=fr"/>
- <to uri="bean:doSomething"/>
-</route>]]></script>
-</div></div><h2 id="HowDoIConfigureEndpoints?-SeeAlso"><span
style="line-height: 1.5;">See Also</span></h2><ul><li><a shape="rect"
href="how-do-i-add-a-component.html">How do I add a component</a></li><li><a
shape="rect" href="spring.html">Spring</a></li><li><a shape="rect"
href="uris.html">URIs</a></li><li><a shape="rect"
href="using-propertyplaceholder.html">Using
PropertyPlaceholder</a></li></ul></div>
+ ftpClientConfig.serverLanguageCode=fr"/>
+ <to uri="bean:doSomething"/>
+</route></plain-text-body><h2
id="HowDoIConfigureEndpoints?-SeeAlso"><span style="line-height: 1.5;">See
Also</span></h2><ul><li><a shape="rect"
href="how-do-i-add-a-component.html">How do I add a component</a></li><li><a
shape="rect" href="spring.html">Spring</a></li><li><a shape="rect"
href="uris.html">URIs</a></li><li><a shape="rect"
href="using-propertyplaceholder.html">Using
PropertyPlaceholder</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified:
websites/production/camel/content/how-do-i-import-routes-from-other-xml-files.html
==============================================================================
---
websites/production/camel/content/how-do-i-import-routes-from-other-xml-files.html
(original)
+++
websites/production/camel/content/how-do-i-import-routes-from-other-xml-files.html
Fri Aug 25 08:22:01 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: How Do I Import Routes From Other XML Files?
@@ -86,49 +75,7 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="HowDoIImportRoutesFromOtherXMLFiles?-HowDoIImportRoutesFromOtherXMLFiles?">How
Do I Import Routes From Other XML Files?</h2><p><strong>Available as of Camel
2.3</strong></p><p>When defining routes in Camel using <a shape="rect"
href="xml-configuration.html">Xml Configuration</a> you may want to define some
routes in other XML files. For example you may have many routes and it may help
to maintain the application if some of the routes are in separate XML files.
You may also want to store common and reusable routes in other XML files, which
you can simply import when needed.</p><p>In <strong>Camel 2.3</strong> it is
now possible to define routes outside
<strong><code><camelContext/></code></strong> which you do in a new
<strong><code><routeContext/></code></strong> tag.</p><div
class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-informat
ion-macro-icon"></span><div
class="confluence-information-macro-body"><p><strong>Notice:</strong> When you
use <strong><code><routeContext></code></strong> then they are
separated, and cannot reuse existing
<strong><code><onException></code></strong>,
<strong><code><intercept></code></strong>, <strong><code><dataFormats></code></strong>
and similar cross cutting functionality defined in the
<strong><code><camelContext></code></strong>. In other words
the <strong><code><routeContext></code></strong> is currently
isolated. This may change in Camel 3.x.</p></div></div><p>For example we could
have a file named <strong><code>myCoolRoutes.xml</code></strong> which contains
a couple of routes as shown:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>myCoolRoutes.xml</b></div><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="
- 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
- ">
-
- <!-- this is an included XML file where we only the the routeContext
-->
- <routeContext id="myCoolRoutes"
xmlns="http://camel.apache.org/schema/spring">
- <!-- we can have a route -->
- <route id="cool">
- <from uri="direct:start"/>
- <to uri="mock:result"/>
- </route>
- <!-- and another route, you can have as many your like -->
- <route id="bar">
- <from uri="direct:bar"/>
- <to uri="mock:bar"/>
- </route>
- </routeContext>
-
-</beans>
-]]></script>
-</div></div>Then in your XML file which contains the CamelContext you can use
Spring to import the <strong><code>myCoolRoute.xml</code></strong> file. And
then inside <strong><code><camelContext/></code></strong> you can refer
to the <strong><code><routeContext/></code></strong> by
its <strong><code>id</code></strong> as shown below:<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[
-<!-- import the routes from another XML file -->
-<import resource="myCoolRoutes.xml"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
-
- <!-- refer to a given route to be used -->
- <routeContextRef ref="myCoolRoutes"/>
-
- <!-- we can of course still use routes inside camelContext -->
- <route id="inside">
- <from uri="direct:inside"/>
- <to uri="mock:inside"/>
- </route>
-</camelContext>
-]]></script>
-</div></div>Also notice that you can mix and match, having routes
inside <strong><code>CamelContext</code></strong> and also externalized in
<strong><code>RouteContext</code></strong>.<p>You can have as many
<strong><code><routeContextRef/></code></strong> as you like.</p><div
class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Reusable routes</p><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The routes defined in
<strong><code><routeContext/></code></strong> can be reused by multiple
<strong><code><camelContext/></code></strong>. However its only the
definition which is reused. At runtime
each <strong><code>CamelContext</code></strong> will create its own
instance of the route based on the definition.</p></div></div></div>
+<div class="wiki-content maincontent"><h2
id="HowDoIImportRoutesFromOtherXMLFiles?-HowDoIImportRoutesFromOtherXMLFiles?">How
Do I Import Routes From Other XML Files?</h2><p><strong>Available as of Camel
2.3</strong></p><p>When defining routes in Camel using <a shape="rect"
href="xml-configuration.html">Xml Configuration</a> you may want to define some
routes in other XML files. For example you may have many routes and it may help
to maintain the application if some of the routes are in separate XML files.
You may also want to store common and reusable routes in other XML files, which
you can simply import when needed.</p><p>In <strong>Camel 2.3</strong> it is
now possible to define routes outside
<strong><code><camelContext/></code></strong> which you do in a new
<strong><code><routeContext/></code></strong>
tag.</p><rich-text-body><p><strong>Notice:</strong> When you
use <strong><code><routeContext></code></strong> then they are
separated, and cannot reuse ex
isting <strong><code><onException></code></strong>,
<strong><code><intercept></code></strong>, <strong><code><dataFormats></code></strong>
and similar cross cutting functionality defined in the
<strong><code><camelContext></code></strong>. In other words
the <strong><code><routeContext></code></strong> is currently
isolated. This may change in Camel 3.x.</p></rich-text-body><p>For example we
could have a file named <strong><code>myCoolRoutes.xml</code></strong> which
contains a couple of routes as
shown:<plain-text-body>{snippet:id=e1|lang=xml|title=myCoolRoutes.xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/myCoolRoutes.xml}</plain-text-body>Then
in your XML file which contains the CamelContext you can use Spring to import
the <strong><code>myCoolRoute.xml</code></strong> file. And then inside
<strong><code><camelContext/></code></strong> you can refer to the
<strong><code><routeContext/
></code></strong> by its <strong><code>id</code></strong> as shown
below:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml}</plain-text-body>Also
notice that you can mix and match, having routes
inside <strong><code>CamelContext</code></strong> and also externalized in
<strong><code>RouteContext</code></strong>.</p><p>You can have as many
<strong><code><routeContextRef/></code></strong> as you
like.</p><parameter ac:name="title">Reusable
routes</parameter><rich-text-body><p>The routes defined in
<strong><code><routeContext/></code></strong> can be reused by multiple
<strong><code><camelContext/></code></strong>. However its only the
definition which is reused. At runtime
each <strong><code>CamelContext</code></strong> will create its own
instance of the route based on the definition.</p></rich-text-body></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/idempotent-consumer.html
==============================================================================
--- websites/production/camel/content/idempotent-consumer.html (original)
+++ websites/production/camel/content/idempotent-consumer.html Fri Aug 25
08:22:01 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: Idempotent Consumer
@@ -86,93 +75,10 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h3
id="IdempotentConsumer-IdempotentConsumer">Idempotent Consumer</h3><p>The <a
shape="rect" class="external-link"
href="http://www.enterpriseintegrationpatterns.com/IdempotentReceiver.html"
rel="nofollow">Idempotent Consumer</a> from the <a shape="rect"
href="enterprise-integration-patterns.html">EIP patterns</a> is used to filter
out duplicate messages.</p><p>This pattern is implemented using the <a
shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/idempotent/IdempotentConsumer.html">IdempotentConsumer</a>
class. This uses an <a shape="rect" href="expression.html">Expression</a> to
calculate a unique message ID string for a given message exchange; this ID can
then be looked up in the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/IdempotentRepository.html">IdempotentRepository</a>
to see if it h
as been seen before; if it has the message is consumed; if its not then the
message is processed and the ID is added to the repository.</p><p>The
Idempotent Consumer essentially acts like a <a shape="rect"
href="message-filter.html">Message Filter</a> to filter out
duplicates.</p><p>Camel will add the message id eagerly to the repository to
detect duplication also for Exchanges currently in progress.<br clear="none">
On completion Camel will remove the message id from the repository if the
Exchange failed, otherwise it stays there.</p><p>Camel provides the following
Idempotent Consumer implementations:</p><ul
class="alternate"><li>MemoryIdempotentRepository</li><li><a shape="rect"
href="file2.html">FileIdempotentRepository</a></li><li><a shape="rect"
href="hazelcast-component.html">HazelcastIdempotentRepository</a>
(<strong>Available as of Camel 2.8</strong>)</li><li><a shape="rect"
href="sql-component.html">JdbcMessageIdRepository</a> (<strong>Available as of
Camel 2.7</strong>)</l
i><li><a shape="rect" href="jpa.html">JpaMessageIdRepository</a></li><li><p><a
shape="rect" href="infinispan.html">InfinispanIdempotentRepository</a>
(<strong>Available as of Camel 2.13.0)</strong></p></li><li><p><a shape="rect"
href="jcache.html">JCacheIdempotentRepository</a><strong> (<strong>Available
as of Camel 2.17.0)</strong></strong></p></li><li><p><a shape="rect"
href="spring.html">SpringCacheIdempotentRepository</a> <strong>(<strong>Available
as of Camel 2.17.1)</strong></strong><strong><strong><br
clear="none"></strong></strong></p></li><li><p><a shape="rect"
href="ehcache.html">EhcacheIdempotentRepository</a><strong><strong> <strong>(<strong>Available
as of Camel 2.18.0)</strong></strong></strong></strong></p></li><li><a
shape="rect" href="kafka.html">KafkaIdempotentRepository</a> (<strong>Available
as of Camel 2.19.0)</strong></li></ul><h3
id="IdempotentConsumer-Options">Options</h3><p>The Idempotent Consumer has the
following options:</p><div class="tabl
e-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</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>eager</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>true</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Eager controls whether Camel adds the message to the
repository before or after the exchange has been processed. If enabled before
then Camel will be able to detect duplicate messages even when messages are
currently in progress. By disabling Camel will only detect duplicates when a
message has successfully been processed.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>messageIdRepositoryRef</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluence
Td"><p>A reference to a <code>IdempotentRepository</code> to lookup in the
registry. This option is mandatory when using XML DSL.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>skipDuplicate</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>true</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> Sets whether to
skip duplicate messages. If set to <code>false</code> then the message will be
continued. However the <a shape="rect" href="exchange.html">Exchange</a> has
been marked as a duplicate by having the <code>Exchange.DUPLICATE_MESSAG</code>
exchange property set to a <code>Boolean.TRUE</code>
value.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>removeOnFailure</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>true</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.9:</strong> Sets whether to remove the
id of an Exchange that failed.</p></td></tr><tr><td co
lspan="1" rowspan="1" class="confluenceTd">completionEager</td><td colspan="1"
rowspan="1" class="confluenceTd">false</td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.16:</strong> Sets whether to complete
the idempotent consumer eager or when the exchange is done.</p><p>If this
option is true to complete eager, then the idempotent consumer will trigger its
completion when the exchange reached the end of the block of the idempotent
consumer pattern. So if the exchange is continued routed after the block ends,
then whatever happens there does not affect the state.</p><p>If this option is
false (default) to not complete eager, then the idempotent consumer will
complete when the exchange is done being routed. So if the exchange is
continued routed after the block ends, then whatever happens there also affect
the state. For example if the exchange failed due to an exception, then the
state of the idempotent consumer will be a
rollback.</p></td></tr></tbody></table>
</div><h3 id="IdempotentConsumer-Usingthe"><strong>Using the <a shape="rect"
href="fluent-builders.html">Fluent Builders</a></strong></h3><p>The following
example will use the header <strong>myMessageId</strong> to filter out
duplicates</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[
-RouteBuilder builder = new RouteBuilder() {
- public void configure() {
- errorHandler(deadLetterChannel("mock:error"));
+<div class="wiki-content maincontent"><h3
id="IdempotentConsumer-IdempotentConsumer">Idempotent Consumer</h3><p>The <a
shape="rect" class="external-link"
href="http://www.enterpriseintegrationpatterns.com/IdempotentReceiver.html"
rel="nofollow">Idempotent Consumer</a> from the <a shape="rect"
href="enterprise-integration-patterns.html">EIP patterns</a> is used to filter
out duplicate messages.</p><p>This pattern is implemented using the <a
shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/idempotent/IdempotentConsumer.html">IdempotentConsumer</a>
class. This uses an <a shape="rect" href="expression.html">Expression</a> to
calculate a unique message ID string for a given message exchange; this ID can
then be looked up in the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/IdempotentRepository.html">IdempotentRepository</a>
to see if it h
as been seen before; if it has the message is consumed; if its not then the
message is processed and the ID is added to the repository.</p><p>The
Idempotent Consumer essentially acts like a <a shape="rect"
href="message-filter.html">Message Filter</a> to filter out
duplicates.</p><p>Camel will add the message id eagerly to the repository to
detect duplication also for Exchanges currently in progress.<br clear="none">
On completion Camel will remove the message id from the repository if the
Exchange failed, otherwise it stays there.</p><p>Camel provides the following
Idempotent Consumer implementations:</p><ul
class="alternate"><li>MemoryIdempotentRepository</li><li><a shape="rect"
href="file2.html">FileIdempotentRepository</a></li><li><a shape="rect"
href="hazelcast-component.html">HazelcastIdempotentRepository</a>
(<strong>Available as of Camel 2.8</strong>)</li><li><a shape="rect"
href="sql-component.html">JdbcMessageIdRepository</a> (<strong>Available as of
Camel 2.7</strong>)</l
i><li><a shape="rect" href="jpa.html">JpaMessageIdRepository</a></li><li><p><a
shape="rect" href="infinispan.html">InfinispanIdempotentRepository</a>
(<strong>Available as of Camel 2.13.0)</strong></p></li><li><p><a shape="rect"
href="jcache.html">JCacheIdempotentRepository</a><strong> (<strong>Available
as of Camel 2.17.0)</strong></strong></p></li><li><p><a shape="rect"
href="spring.html">SpringCacheIdempotentRepository</a> <strong>(<strong>Available
as of Camel 2.17.1)</strong></strong><strong><strong><br
clear="none"></strong></strong></p></li><li><p><a shape="rect"
href="ehcache.html">EhcacheIdempotentRepository</a><strong><strong> <strong>(<strong>Available
as of Camel 2.18.0)</strong></strong></strong></strong></p></li><li><a
shape="rect" href="kafka.html">KafkaIdempotentRepository</a> (<strong>Available
as of Camel 2.19.0)</strong></li></ul><h3
id="IdempotentConsumer-Options">Options</h3><p>The Idempotent Consumer has the
following options:</p><div class="tabl
e-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</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>eager</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>true</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Eager controls whether Camel adds the message to the
repository before or after the exchange has been processed. If enabled before
then Camel will be able to detect duplicate messages even when messages are
currently in progress. By disabling Camel will only detect duplicates when a
message has successfully been processed.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>messageIdRepositoryRef</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluence
Td"><p>A reference to a <code>IdempotentRepository</code> to lookup in the
registry. This option is mandatory when using XML DSL.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>skipDuplicate</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>true</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> Sets whether to
skip duplicate messages. If set to <code>false</code> then the message will be
continued. However the <a shape="rect" href="exchange.html">Exchange</a> has
been marked as a duplicate by having the <code>Exchange.DUPLICATE_MESSAG</code>
exchange property set to a <code>Boolean.TRUE</code>
value.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>removeOnFailure</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>true</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.9:</strong> Sets whether to remove the
id of an Exchange that failed.</p></td></tr><tr><td co
lspan="1" rowspan="1" class="confluenceTd">completionEager</td><td colspan="1"
rowspan="1" class="confluenceTd">false</td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.16:</strong> Sets whether to complete
the idempotent consumer eager or when the exchange is done.</p><p>If this
option is true to complete eager, then the idempotent consumer will trigger its
completion when the exchange reached the end of the block of the idempotent
consumer pattern. So if the exchange is continued routed after the block ends,
then whatever happens there does not affect the state.</p><p>If this option is
false (default) to not complete eager, then the idempotent consumer will
complete when the exchange is done being routed. So if the exchange is
continued routed after the block ends, then whatever happens there also affect
the state. For example if the exchange failed due to an exception, then the
state of the idempotent consumer will be a
rollback.</p></td></tr></tbody></table>
</div><h3 id="IdempotentConsumer-Usingthe"><strong>Using the <a shape="rect"
href="fluent-builders.html">Fluent Builders</a></strong></h3><p>The following
example will use the header <strong>myMessageId</strong> to filter out
duplicates<plain-text-body>{snippet:id=idempotent|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java}</plain-text-body>The
above <a shape="rect" class="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java">example</a>
will use an in-memory based <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/idempotent/MessageIdRepository.html">MessageIdRepository</a>
which can easily run out of memory and doesn't work in a clustered
environment. So you might prefer to use the JPA based implementation which uses
a database to store the message IDs which have been proce
ssed<plain-text-body>{snippet:id=idempotent|lang=java|url=camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaIdempotentConsumerTest.java}</plain-text-body>In
the above <a shape="rect" class="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaIdempotentConsumerTest.java">example</a>
we are using the header <strong>messageId</strong> to filter out duplicates
and using the collection <strong>myProcessorName</strong> to indicate the
Message ID Repository to use. This name is important as you could process the
same message by many different processors; so each may require its own logical
Message ID Repository.</p><p>For further examples of this pattern in use you
could look at the <a shape="rect" class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerTest.java?view=markup">junit
test case</a><
/p><h3 id="IdempotentConsumer-SpringXMLexample">Spring XML example</h3><p>The
following example will use the header <strong>myMessageId</strong> to filter
out
duplicates<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringIdempotentConsumerTest.xml}</plain-text-body></p><h3
id="IdempotentConsumer-Howtohandleduplicatemessagesintheroute">How to handle
duplicate messages in the route</h3><p><strong>Available as of Camel
2.8</strong></p><p>You can now set the <code>skipDuplicate</code> option to
<code>false</code> which instructs the idempotent consumer to route duplicate
messages as well. However the duplicate message has been marked as duplicate by
having a property on the <a shape="rect" href="exchange.html">Exchange</a> set
to true. We can leverage this fact by using a <a shape="rect"
href="content-based-router.html">Content Based Router</a> or <a shape="rect"
href="message-filter.html">Message Fi
lter</a> to detect this and handle duplicate messages.</p><p>For example in
the following example we use the <a shape="rect"
href="message-filter.html">Message Filter</a> to send the message to a
duplicate endpoint, and then stop continue routing that
message.<plain-text-body>{snippet:id=e1|lang=java|title=Filter duplicate
messages|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerTest.java}</plain-text-body>The
sample example in XML DSL would
be:<plain-text-body>{snippet:id=e1|lang=xml|title=Filter duplicate
messages|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringIdempotentConsumerNoSkipDuplicateFilterTest.xml}</plain-text-body></p><h3
id="IdempotentConsumer-Howtohandleduplicatemessageinaclusteredenvironmentwithadatagrid">How
to handle duplicate message in a clustered environment with a data
grid</h3><p><strong>Available as of Camel 2.8</strong></p><p>If you have
running Camel in a clustered env
ironment, a in memory idempotent repository doesn't work (see above). You can
setup either a central database or use the idempotent consumer implementation
based on the <a shape="rect" class="external-link"
href="http://www.hazelcast.com/" rel="nofollow">Hazelcast</a> data grid.
Hazelcast finds the nodes over multicast (which is default - configure
Hazelcast for tcp-ip) and creates automatically a map based
repository:</p><parameter ac:name="">java</parameter><plain-text-body>
HazelcastIdempotentRepository idempotentRepo = new
HazelcastIdempotentRepository("myrepo");
- from("direct:a")
- .idempotentConsumer(header("myMessageId"),
- MemoryIdempotentRepository.memoryIdempotentRepository(200))
- .to("direct:b");
- }
-};
-]]></script>
-</div></div>The above <a shape="rect" class="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java">example</a>
will use an in-memory based <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/idempotent/MessageIdRepository.html">MessageIdRepository</a>
which can easily run out of memory and doesn't work in a clustered
environment. So you might prefer to use the JPA based implementation which uses
a database to store the message IDs which have been processed<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:start").idempotentConsumer(
- header("messageId"),
- jpaMessageIdRepository(lookup(EntityManagerFactory.class),
PROCESSOR_NAME)
-).to("mock:result");
-]]></script>
-</div></div>In the above <a shape="rect" class="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/processor/jpa/JpaIdempotentConsumerTest.java">example</a>
we are using the header <strong>messageId</strong> to filter out duplicates
and using the collection <strong>myProcessorName</strong> to indicate the
Message ID Repository to use. This name is important as you could process the
same message by many different processors; so each may require its own logical
Message ID Repository.<p>For further examples of this pattern in use you could
look at the <a shape="rect" class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/IdempotentConsumerTest.java?view=markup">junit
test case</a></p><h3 id="IdempotentConsumer-SpringXMLexample">Spring XML
example</h3><p>The following example will use the header
<strong>myMessageId</strong> to filter out duplicates</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[
-<!-- repository for the idempotent consumer -->
-<bean id="myRepo"
class="org.apache.camel.processor.idempotent.MemoryIdempotentRepository"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <idempotentConsumer messageIdRepositoryRef="myRepo">
- <!-- use the messageId header as key for identifying duplicate
messages -->
- <header>messageId</header>
- <!-- if not a duplicate send it to this mock endpoint -->
- <to uri="mock:result"/>
- </idempotentConsumer>
- </route>
-</camelContext>
-]]></script>
-</div></div><h3
id="IdempotentConsumer-Howtohandleduplicatemessagesintheroute">How to handle
duplicate messages in the route</h3><p><strong>Available as of Camel
2.8</strong></p><p>You can now set the <code>skipDuplicate</code> option to
<code>false</code> which instructs the idempotent consumer to route duplicate
messages as well. However the duplicate message has been marked as duplicate by
having a property on the <a shape="rect" href="exchange.html">Exchange</a> set
to true. We can leverage this fact by using a <a shape="rect"
href="content-based-router.html">Content Based Router</a> or <a shape="rect"
href="message-filter.html">Message Filter</a> to detect this and handle
duplicate messages.</p><p>For example in the following example we use the <a
shape="rect" href="message-filter.html">Message Filter</a> to send the message
to a duplicate endpoint, and then stop continue routing that message.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeHeader pane
lHeader pdl" style="border-bottom-width: 1px;"><b>Filter duplicate
messages</b></div><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:start")
- // instruct idempotent consumer to not skip duplicates as we will filter
then our self
-
.idempotentConsumer(header("messageId")).messageIdRepository(repo).skipDuplicate(false)
- .filter(property(Exchange.DUPLICATE_MESSAGE).isEqualTo(true))
- // filter out duplicate messages by sending them to someplace else and
then stop
- .to("mock:duplicate")
- .stop()
- .end()
- // and here we process only new messages (no duplicates)
- .to("mock:result");
-]]></script>
-</div></div>The sample example in XML DSL would be:<div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Filter duplicate messages</b></div><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-
-<!-- idempotent repository, just use a memory based for testing -->
-<bean id="myRepo"
class="org.apache.camel.processor.idempotent.MemoryIdempotentRepository"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <!-- we do not want to skip any duplicate messages -->
- <idempotentConsumer messageIdRepositoryRef="myRepo"
skipDuplicate="false">
- <!-- use the messageId header as key for identifying duplicate
messages -->
- <header>messageId</header>
- <!-- we will to handle duplicate messages using a filter -->
- <filter>
- <!-- the filter will only react on duplicate messages, if
this property is set on the Exchange -->
-
<exchangeProperty>CamelDuplicateMessage</exchangeProperty>
- <!-- and send the message to this mock, due its part of an
unit test -->
- <!-- but you can of course do anything as its part of the
route -->
- <to uri="mock:duplicate"/>
- <!-- and then stop -->
- <stop/>
- </filter>
- <!-- here we route only new messages -->
- <to uri="mock:result"/>
- </idempotentConsumer>
- </route>
-</camelContext>
-]]></script>
-</div></div><h3
id="IdempotentConsumer-Howtohandleduplicatemessageinaclusteredenvironmentwithadatagrid">How
to handle duplicate message in a clustered environment with a data
grid</h3><p><strong>Available as of Camel 2.8</strong></p><p>If you have
running Camel in a clustered environment, a in memory idempotent repository
doesn't work (see above). You can setup either a central database or use the
idempotent consumer implementation based on the <a shape="rect"
class="external-link" href="http://www.hazelcast.com/"
rel="nofollow">Hazelcast</a> data grid. Hazelcast finds the nodes over
multicast (which is default - configure Hazelcast for tcp-ip) and creates
automatically a map based repository:</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[ HazelcastIdempotentRepository
idempotentRepo = new HazelcastIdempotentRepository("myrepo");
-
-
from("direct:in").idempotentConsumer(header("messageId"),
idempotentRepo).to("mock:out");
-]]></script>
-</div></div><p>You have to define how long the repository should hold each
message id (default is to delete it never). To avoid that you run out of memory
you should create an eviction strategy based on the <a shape="rect"
class="external-link"
href="http://www.hazelcast.com/documentation.jsp#MapEviction"
rel="nofollow">Hazelcast configuration</a>. For additional information see <a
shape="rect" href="hazelcast-component.html">camel-hazelcast</a>.</p><p>See
this <a shape="rect"
href="hazelcast-idempotent-repository-tutorial.html">little tutorial</a>, how
setup such an idempotent repository on two cluster nodes using Apache
Karaf.</p><p><strong>Available as of Camel <strong>
2.13.0</strong></strong></p><p>Another option for using Idempotent Consumer in
a clustered environment is Infinispan. Infinispan is a data grid with
replication and distribution clustering support. For additional information
see<strong> <a shape="rect" href="infinispan.html">camel-infinispan</a>.<br
clear="none"><
/strong></p><p></p><h4 id="IdempotentConsumer-UsingThisPattern">Using This
Pattern</h4>
-
-<p>If you would like to use this EIP Pattern then please read the <a
shape="rect" href="getting-started.html">Getting Started</a>, you may also find
the <a shape="rect" href="architecture.html">Architecture</a> useful
particularly the description of <a shape="rect"
href="endpoint.html">Endpoint</a> and <a shape="rect"
href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect"
href="examples.html">Examples</a> first before trying this pattern
out.</p></div>
+ from("direct:in").idempotentConsumer(header("messageId"),
idempotentRepo).to("mock:out");
+</plain-text-body><p>You have to define how long the repository should hold
each message id (default is to delete it never). To avoid that you run out of
memory you should create an eviction strategy based on the <a shape="rect"
class="external-link"
href="http://www.hazelcast.com/documentation.jsp#MapEviction"
rel="nofollow">Hazelcast configuration</a>. For additional information see <a
shape="rect" href="hazelcast-component.html">camel-hazelcast</a>.</p><p>See
this <a shape="rect"
href="hazelcast-idempotent-repository-tutorial.html">little tutorial</a>, how
setup such an idempotent repository on two cluster nodes using Apache
Karaf.</p><p><strong>Available as of Camel <strong>
2.13.0</strong></strong></p><p>Another option for using Idempotent Consumer in
a clustered environment is Infinispan. Infinispan is a data grid with
replication and distribution clustering support. For additional information
see<strong> <a shape="rect" href="infinispan.html">camel-infinispan</a>.<br
clear="n
one"></strong></p><p><parameter ac:name=""><a shape="rect"
href="using-this-pattern.html">Using This Pattern</a></parameter></p></div>
</td>
<td valign="top">
<div class="navigation">