Modified: websites/production/camel/content/stringtemplate.html
==============================================================================
--- websites/production/camel/content/stringtemplate.html (original)
+++ websites/production/camel/content/stringtemplate.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: StringTemplate
@@ -86,78 +75,30 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="StringTemplate-StringTemplate">String Template</h2><p>The
<strong><code>string-template:</code></strong> component allows you to process
a message using a <a shape="rect" class="external-link"
href="http://www.stringtemplate.org/" rel="nofollow">String Template</a>. This
can be ideal when using <a shape="rect" href="templating.html">Templating</a>
to generate responses for requests.</p><p>Maven users will need to add the
following dependency to their <strong><code>pom.xml</code></strong> for this
component:</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[<dependency>
+<div class="wiki-content maincontent"><h2
id="StringTemplate-StringTemplate">String Template</h2><p>The
<strong><code>string-template:</code></strong> component allows you to process
a message using a <a shape="rect" class="external-link"
href="http://www.stringtemplate.org/" rel="nofollow">String Template</a>. This
can be ideal when using <a shape="rect" href="templating.html">Templating</a>
to generate responses for requests.</p><p>Maven users will need to add the
following dependency to their <strong><code>pom.xml</code></strong> for this
component:</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stringtemplate</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
-]]></script>
-</div></div><h3 id="StringTemplate-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[string-template:templateName[?options]
-]]></script>
-</div></div><p>Where <strong><code>templateName</code></strong> is the
classpath-local URI of the template to invoke; or the complete URL of the
remote template.</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="StringTemplate-Options">Options</h3><div class="confluenceTableSmall"><div
class="table-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><code>contentCache</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Cache for the resource content
when its loaded. <br clear="none" class="atl-forced-newline"> <strong>Note</str
ong>: as of <strong>Camel 2.9</strong> cached resource content can be cleared
via JMX using the endpoint's <strong><code>clearContentCache</code></strong>
operation.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>delimiterStart</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>From<strong> Camel 2.11.1</strong>:
configuring the variable start delimiter</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>delimiterStop</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>From<strong> Camel
2.11.1</strong>: configuring the variable end
delimiter</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="StringTemplate-Headers">Headers</h3><p>Camel will store a reference to
the resource in the message header with key,
<strong><code>org.apache.camel.stringtemplate.resource</code></strong>. The
Resource is an
<strong><code>org.springframework.core.io.Resource</code></strong>
object.</p><h3 id="StringTemplate-Hot-Reloading">Hot-Reloading</h3><p>The
string template resource is by default hot-reloadable for both file and
classpath resources (expanded jar). If you set
<strong><code>contentCache=true</code></strong>, Camel will load the resource
just once, disabling hot-reloading. This scenario can be used in production
when the resource never changes.</p><h3
id="StringTemplate-StringTemplateAttributes">StringTemplate
Attributes</h3><p>Camel will provide exchange information as attributes (just a
<strong><code>java.util.Map</code></strong>) to the string template. The
Exchange is transferred as:</p><div class="confluenceTableSmall"><div
class="table-wrap"><table class="confluenceTa
ble"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Key</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exchange</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The Exchange itself.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>headers</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The headers of
the <strong><code>IN</code></strong> message.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>camelContext</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The Camel Context.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>request</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The <strong><code>IN</code></strong>
message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>in</code></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>IN</code></strong>
message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>body</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>IN</code></strong> message
body.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>out</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>OUT</code></strong> message
(only for <strong><code>InOut</code></strong> message exchange
pattern).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>response</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The <strong><code>OUT</code></strong>
message (only for <strong><code>InOut</code></strong> message exchange
pattern).</p></td></tr></tbody></table></div></div>
-
-
-<p>From <strong>Camel 2.14</strong>: you can define the custom context map by
setting the message
header <strong><code>CamelStringTemplateVariableMap</code></strong>, as
shown below:</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[Map<String, Object> variableMap = new
HashMap<String, Object>();
+</plain-text-body><h3 id="StringTemplate-URIFormat">URI
Format</h3><plain-text-body>string-template:templateName[?options]
+</plain-text-body><p>Where <strong><code>templateName</code></strong> is
the classpath-local URI of the template to invoke; or the complete URL of the
remote template.</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="StringTemplate-Options">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-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><code>contentCache</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Cache for the resource content
when its loaded. <br clear="none
" class="atl-forced-newline"> <strong>Note</strong>: as of <strong>Camel
2.9</strong> cached resource content can be cleared via JMX using the
endpoint's <strong><code>clearContentCache</code></strong>
operation.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>delimiterStart</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>From<strong> Camel 2.11.1</strong>:
configuring the variable start delimiter</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>delimiterStop</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>From<strong> Camel
2.11.1</strong>: configuring the variable end
delimiter</p></td></tr></tbody></table></div></rich-text-body><h3
id="StringTemplate-Headers">Headers</h3><p>Camel will store a reference to the
resource in the message head
er with key,
<strong><code>org.apache.camel.stringtemplate.resource</code></strong>. The
Resource is an
<strong><code>org.springframework.core.io.Resource</code></strong>
object.</p><h3 id="StringTemplate-Hot-Reloading">Hot-Reloading</h3><p>The
string template resource is by default hot-reloadable for both file and
classpath resources (expanded jar). If you set
<strong><code>contentCache=true</code></strong>, Camel will load the resource
just once, disabling hot-reloading. This scenario can be used in production
when the resource never changes.</p><h3
id="StringTemplate-StringTemplateAttributes">StringTemplate
Attributes</h3><p>Camel will provide exchange information as attributes (just a
<strong><code>java.util.Map</code></strong>) to the string template. The
Exchange is transferred as:</p><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Ke
y</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>exchange</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The Exchange itself.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>headers</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The headers of
the <strong><code>IN</code></strong> message.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>camelContext</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The Camel Context.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>request</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The <strong><code>IN</code></strong>
message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>in</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><cod
e>IN</code></strong> message.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>body</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>IN</code></strong> message
body.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>out</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The <strong><code>OUT</code></strong> message
(only for <strong><code>InOut</code></strong> message exchange
pattern).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>response</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The <strong><code>OUT</code></strong>
message (only for <strong><code>InOut</code></strong> message exchange
pattern).</p></td></tr></tbody></table></div></rich-text-body><p>From
<strong>Camel 2.14</strong>: you can define the custom context map by setting
the message header <strong><code>CamelStringTemplateVariableMap</c
ode></strong>, as shown below:</p><parameter
ac:name="language">java</parameter><plain-text-body>Map<String, Object>
variableMap = new HashMap<String, Object>();
Map<String, Object> headersMap = new HashMap<String, Object>();
-headersMap.put("name", "Willem");
-variableMap.put("headers", headersMap);
-variableMap.put("body", "Monday");
-variableMap.put("exchange", exchange);
-exchange.getIn().setHeader("CamelStringTemplateVariableMap",
variableMap);
-
-]]></script>
-</div></div><h3 id="StringTemplate-Samples">Samples</h3><p>For example you
could use a string template as follows in order to formulate a response to a
message:</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("activemq:My.Queue")
- .to("string-template:com/acme/MyResponse.tm");
-]]></script>
-</div></div><h3 id="StringTemplate-TheEmailSample">The Email Sample</h3><p>In
this sample we want to use a string template to send an order confirmation
email. The email template is laid out in
<strong><code>StringTemplate</code></strong> as:<br clear="none"> This example
works for <strong>camel 2.11.0</strong>. If your camel version is less than
<strong>2.11.0</strong>, the variables should be started and ended with
<strong><code>$</code></strong>.</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[Dear <headers.lastName>,
<headers.firstName>
+headersMap.put("name", "Willem");
+variableMap.put("headers", headersMap);
+variableMap.put("body", "Monday");
+variableMap.put("exchange", exchange);
+exchange.getIn().setHeader("CamelStringTemplateVariableMap", variableMap);
+
+</plain-text-body><h3 id="StringTemplate-Samples">Samples</h3><p>For example
you could use a string template as follows in order to formulate a response to
a message:</p><plain-text-body>from("activemq:My.Queue")
+ .to("string-template:com/acme/MyResponse.tm");
+</plain-text-body><h3 id="StringTemplate-TheEmailSample">The Email
Sample</h3><p>In this sample we want to use a string template to send an order
confirmation email. The email template is laid out in
<strong><code>StringTemplate</code></strong> as:<br clear="none"> This example
works for <strong>camel 2.11.0</strong>. If your camel version is less than
<strong>2.11.0</strong>, the variables should be started and ended with
<strong><code>$</code></strong>.</p><plain-text-body>Dear
<headers.lastName>, <headers.firstName>
Thanks for the order of <headers.item>.
Regards Camel Riders Bookstore
<body>
-]]></script>
-</div></div><p>And the java code is 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[
-private Exchange createLetter() {
- Exchange exchange =
context.getEndpoint("direct:a").createExchange();
- Message msg = exchange.getIn();
- msg.setHeader("firstName", "Claus");
- msg.setHeader("lastName", "Ibsen");
- msg.setHeader("item", "Camel in Action");
- msg.setBody("PS: Next beer is on me, James");
- return exchange;
-}
-
-@Test
-public void testVelocityLetter() throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMessageCount(1);
- mock.expectedBodiesReceived("Dear Ibsen, Claus! Thanks for the order
of Camel in Action. Regards Camel Riders Bookstore PS: Next beer is on me,
James");
-
- template.send("direct:a", createLetter());
-
- mock.assertIsSatisfied();
-}
-
-protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() throws Exception {
-
from("direct:a").to("string-template:org/apache/camel/component/stringtemplate/letter.tm").to("mock:result");
- }
- };
-}
-]]></script>
-</div></div><h3 id="StringTemplate-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></div>
+</plain-text-body><p>And the java code is as
follows:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateLetterTest.java}</plain-text-body><parameter
ac:name=""><a shape="rect" href="endpoint-see-also.html">Endpoint See
Also</a></parameter></p></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/testing.html
==============================================================================
--- websites/production/camel/content/testing.html (original)
+++ websites/production/camel/content/testing.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: Testing
@@ -86,338 +75,7 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="Testing-Testing">Testing</h2><p>Testing is a crucial activity in any piece
of software development or integration. Typically Camel Riders use various
different <a shape="rect" href="components.html">technologies</a> wired
together in a variety of <a shape="rect"
href="enterprise-integration-patterns.html">patterns</a> with different <a
shape="rect" href="languages.html">expression languages</a> together with
different forms of <a shape="rect" href="bean-integration.html">Bean
Integration</a> and <a shape="rect" href="dependency-injection.html">Dependency
Injection</a> so its very easy for things to go wrong! <img class="emoticon
emoticon-smile"
src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/smile.png"
data-emoticon-name="smile" alt="(smile)"> . Testing is the crucial weapon to
ensure that things work as you would expect.</p><p>Camel is a Java library so
you can ea
sily wire up tests in whatever unit testing framework you use (JUnit 3.x
(deprecated), 4.x, or TestNG). However the Camel project has tried to make the
testing of Camel as easy and powerful as possible so we have introduced the
following features.</p><h3 id="Testing-TestingMechanisms">Testing
Mechanisms</h3><p>The following mechanisms are supported:</p><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>Component</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="camel-test.html">Camel Test</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-test</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Is a standalone Java library letting you
easily create Camel test cases using a single Java class for all your
configuration and routing without using <a shape="rect"
href="cdi.html">CDI</a>, <a shape="rect" href="spring.html">Spring</a> or <a
shape="rect" href="guice.html">Guice</a> for <a shape="rect"
href="dependency-injection.html">Dependency Injection</a> which does not
require an in-depth knowledge of Spring + Spring Test or Guice.  Supports
JUnit 3.x (deprecated) and JUnit 4.x based tests.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><a shape="rect"
href="cdi-testing.html">CDI Testing</a></td><td colspan="1" rowspan="1"
class="confluenceTd"><code>camel-test-cdi</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Provides a JUnit 4 runner that bootstraps a
test environment using CDI so that you don't have to be familiar with any CDI
testing frameworks and can concentrate on the testing logic of your Camel CDI
applications. Testing frameworks like <a shape="rect"
class="external-link" href="http://arquillian.org/" rel="nofollow">Arquillian
</a> or <a shape="rect" class="external-link"
href="https://ops4j1.jira.com/wiki/display/PAXEXAM4" rel="nofollow">PAX
Exam</a>, can be used for more advanced test cases, where you need to configure
your system under test in a very fine-grained way or target specific CDI
containers.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" href="spring-testing.html">Spring
Testing</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-test-spring</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Supports JUnit 3.x (deprecated) or JUnit
4.x based tests that bootstrap a test environment using Spring without needing
to be familiar with Spring Test. The plain JUnit 3.x/4.x based tests work very
similar to the test support classes in
<strong><code>camel-test</code></strong>.</p><p>Also supports Spring Test based
tests that use the declarative style of test configuration and injection common
in Spring Test. The Spri
ng Test based tests provide feature parity with the plain JUnit 3.x/4.x based
testing approach.</p><p><strong>Note</strong>:
<strong><code>camel-test-spring</code></strong> is a new component from
<strong>Camel 2.10</strong>. For older Camel release use
<strong><code>camel-test</code></strong> which has built-in <a shape="rect"
href="spring-testing.html">Spring Testing</a>.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="blueprint-testing.html">Blueprint Testing</a></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>camel-test-blueprint</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
Provides the ability to do unit testing on blueprint
configurations</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" href="guice.html">Guice</a></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-guice</code></p></td><td colspan="1"
rowspan="1
" class="confluenceTd"><p><span style="color:
rgb(255,0,0);"><strong>Deprecated</strong></span></p><p>Uses <a shape="rect"
href="guice.html">Guice</a> to dependency inject your test
classes</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>Camel TestNG</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-testng</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><span style="color:
rgb(255,0,0);"><strong>Deprecated</strong></span></p><p>Supports plain TestNG
based tests with or without <a shape="rect"
href="cdi.html">CDI</a>, <a shape="rect"
href="spring.html">Spring</a> or <a shape="rect"
href="guice.html">Guice</a> for <a shape="rect"
href="dependency-injection.html">Dependency Injection</a> which does not
require an in-depth knowledge of CDI, Spring + Spring Test or Guice.
 </p><p>From <strong>Camel 2.10</strong>: this component supports Spring
Test based tests that use the declarati
ve style of test configuration and injection common in Spring Test and
described in more detail under <a shape="rect"
href="spring-testing.html">Spring
Testing</a>.</p></td></tr></tbody></table></div><p>In all approaches the test
classes look pretty much the same in that they all reuse the <a shape="rect"
href="bean-integration.html">Camel binding and injection
annotations</a>.</p><h4 id="Testing-CamelTestExample">Camel Test
Example</h4><p>Here is the <a shape="rect" href="camel-test.html">Camel
Test</a> <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java">example</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[
-// tag::example[]
-public class FilterTest extends CamelTestSupport {
-
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @Override
- public boolean isDumpRouteCoverage() {
- return true;
- }
-
- @Test
- public void testSendMatchingMessage() throws Exception {
- String expectedBody = "<matched/>";
-
- resultEndpoint.expectedBodiesReceived(expectedBody);
-
- template.sendBodyAndHeader(expectedBody, "foo",
"bar");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @Test
- public void testSendNotMatchingMessage() throws Exception {
- resultEndpoint.expectedMessageCount(0);
-
- template.sendBodyAndHeader("<notMatched/>",
"foo", "notMatchedHeaderValue");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- public void configure() {
-
from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
- }
- };
- }
-}
-// end::example[]
-]]></script>
-</div></div>Notice how it derives from the Camel helper class
<strong><code>CamelTestSupport</code></strong> but has no CDI, Spring or Guice
dependency injection configuration but instead overrides the
<strong><code>createRouteBuilder()</code></strong> method.<h4
id="Testing-CDITestExample">CDI Test Example</h4><p>Here is the <a shape="rect"
href="cdi-testing.html">CDI Testing</a> <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java">example</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[
-// tag::example[]
-@RunWith(CamelCdiRunner.class)
-public class FilterTest {
-
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @Before
- public void before() {
- resultEndpoint.reset();
- }
-
- @Test
- public void testSendMatchingMessage() throws Exception {
- String expectedBody = "<matched/>";
-
- resultEndpoint.expectedBodiesReceived(expectedBody);
-
- template.sendBodyAndHeader(expectedBody, "foo",
"bar");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @Test
- public void testSendNotMatchingMessage() throws Exception {
- resultEndpoint.expectedMessageCount(0);
-
- template.sendBodyAndHeader("<notMatched/>",
"foo", "notMatchedHeaderValue");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- static class ContextConfig extends RouteBuilder {
-
- @Override
- public void configure() {
-
from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
- }
- }
-}
-// end::example[]
-]]></script>
-</div></div>You can find more testing patterns illustrated in the
<strong><code>camel-example-cdi-test</code></strong> example and the test
classes that come with it.<h4
id="Testing-SpringTestwithXMLConfigExample">Spring Test with XML Config
Example</h4><p>Here is the <a shape="rect" href="spring-testing.html">Spring
Testing</a> <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java">example
using XML Config</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[
-// tag::example[]
-@ContextConfiguration
-public class FilterTest extends SpringRunWithTestSupport {
-
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @DirtiesContext
- @Test
- public void testSendMatchingMessage() throws Exception {
- String expectedBody = "<matched/>";
-
- resultEndpoint.expectedBodiesReceived(expectedBody);
-
- template.sendBodyAndHeader(expectedBody, "foo",
"bar");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @DirtiesContext
- @Test
- public void testSendNotMatchingMessage() throws Exception {
- resultEndpoint.expectedMessageCount(0);
-
- template.sendBodyAndHeader("<notMatched/>",
"foo", "notMatchedHeaderValue");
-
- resultEndpoint.assertIsSatisfied();
- }
-}
-// end::example[]
-]]></script>
-</div></div>Notice that we use <strong><code>@DirtiesContext</code></strong>
on the test methods to force <a shape="rect" href="spring-testing.html">Spring
Testing</a> to automatically reload the <code><a shape="rect"
href="camelcontext.html">CamelContext</a></code> after each test method - this
ensures that the tests don't clash with each other, e.g., one test method
sending to an endpoint that is then reused in another test method.<p>Also note
the use of <strong><code>@ContextConfiguration</code></strong> to indicate that
by default we should look for the <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/patterns/FilterTest-context.xml"><code>FilterTest-context.xml</code>
on the classpath</a> to configure the test case which 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[
-<!-- tag::example[] -->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- 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
- ">
-
- <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <filter>
- <xpath>$foo = 'bar'</xpath>
- <to uri="mock:result"/>
- </filter>
- </route>
- </camelContext>
-
-</beans>
-<!-- end::example[] -->
-]]></script>
-</div></div><h4 id="Testing-SpringTestwithJavaConfigExample">Spring Test with
Java Config Example</h4><p>Here is the <a shape="rect"
href="spring-testing.html">Spring Testing</a> <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java">example
using Java Config</a>.</p><p>For more information see <a shape="rect"
href="spring-java-config.html">Spring Java Config</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[
-// tag::example[]
-@RunWith(CamelSpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {FilterTest.ContextConfig.class}, loader =
CamelSpringDelegatingTestContextLoader.class)
-public class FilterTest extends AbstractJUnit4SpringContextTests {
-
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
-
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
-
- @DirtiesContext
- @Test
- public void testSendMatchingMessage() throws Exception {
- String expectedBody = "<matched/>";
-
- resultEndpoint.expectedBodiesReceived(expectedBody);
-
- template.sendBodyAndHeader(expectedBody, "foo",
"bar");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @DirtiesContext
- @Test
- public void testSendNotMatchingMessage() throws Exception {
- resultEndpoint.expectedMessageCount(0);
-
- template.sendBodyAndHeader("<notMatched/>",
"foo", "notMatchedHeaderValue");
-
- resultEndpoint.assertIsSatisfied();
- }
-
- @Configuration
- public static class ContextConfig extends SingleRouteCamelConfiguration {
- @Bean
- public RouteBuilder route() {
- return new RouteBuilder() {
- public void configure() {
-
from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
- }
- };
- }
- }
-}
-// end::example[]
-]]></script>
-</div></div>This is similar to the XML Config example above except that there
is no XML file and instead the nested
<strong><code>ContextConfig</code></strong> class does all of the
configuration; so your entire test case is contained in a single Java class. We
currently have to reference by class name this class in the
<strong><code>@ContextConfiguration</code></strong> which is a bit ugly. Please
vote for <a shape="rect" class="external-link"
href="http://jira.springframework.org/browse/SJC-238"
rel="nofollow">SJC-238</a> to address this and make Spring Test work more
cleanly with Spring JavaConfig.<p>Its totally optional but for
the <strong><code>ContextConfig</code></strong> implementation we derive
from <strong><code>SingleRouteCamelConfiguration</code></strong> which is a
helper Spring Java Config class which will configure the
<strong><code>CamelContext</code></strong> for us and then register the
<strong><code>RouteBuilder</code></strong> we create.</p><p>Since <strong>
Camel 2.11.0</strong> you can use the
<strong><code>CamelSpringJUnit4ClassRunner</code></strong> with
<strong><code>CamelSpringDelegatingTestContextLoader</code></strong> like <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java">example
using Java Config with <code>CamelSpringJUnit4ClassRunner</code></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[
-// tag::example[]
-@RunWith(CamelSpringJUnit4ClassRunner.class)
-@ContextConfiguration(
- classes =
{CamelSpringDelegatingTestContextLoaderTest.TestConfig.class},
- // Since Camel 2.11.0
- loader = CamelSpringDelegatingTestContextLoader.class
- )
-@MockEndpoints
-public class CamelSpringDelegatingTestContextLoaderTest {
- @EndpointInject(uri = "mock:direct:end")
- protected MockEndpoint endEndpoint;
-
- @EndpointInject(uri = "mock:direct:error")
- protected MockEndpoint errorEndpoint;
-
- @Produce(uri = "direct:test")
- protected ProducerTemplate testProducer;
-
- @Configuration
- public static class TestConfig extends SingleRouteCamelConfiguration {
- @Bean
- @Override
- public RouteBuilder route() {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
-
from("direct:test").errorHandler(deadLetterChannel("direct:error")).to("direct:end");
-
- from("direct:error").log("Received message
on direct:error endpoint.");
-
- from("direct:end").log("Received message on
direct:end endpoint.");
- }
- };
- }
- }
-
- @Test
- public void testRoute() throws InterruptedException {
- endEndpoint.expectedMessageCount(1);
- errorEndpoint.expectedMessageCount(0);
-
- testProducer.sendBody("<name>test</name>");
-
- endEndpoint.assertIsSatisfied();
- errorEndpoint.assertIsSatisfied();
- }
-}
-// end::example[]
-]]></script>
-</div></div><h4
id="Testing-SpringTestwithXMLConfigandDeclarativeConfigurationExample">Spring
Test with XML Config and Declarative Configuration Example</h4><p>Here is a
Camel test support enhanced <a shape="rect"
href="spring-testing.html">Spring Testing</a> <a shape="rect"
class="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringJUnit4ClassRunnerPlainTest.java">example
using XML Config and pure Spring Test based configuration of the Camel
Context</a>:</p><div class="error"><span class="error">Error formatting macro:
snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span>
</div>Notice how a custom test runner is used with
the <strong><code>@RunWith</code></strong> annotation to support the
features of <strong><code>CamelTestSupport</code></strong> through
annotations on the test class. See <a shape="rect"
href="spring-testing.html">S
pring Testing</a> for a list of annotations you can use in your tests.<h4
id="Testing-BlueprintTest">Blueprint Test</h4><p>Here is the <a shape="rect"
href="blueprint-testing.html">Blueprint Testing</a> <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java">example
using XML Config</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[
-// tag::example[]
-// to use camel-test-blueprint, then extend the CamelBlueprintTestSupport
class,
-// and add your unit tests methods as shown below.
-public class DebugBlueprintTest extends CamelBlueprintTestSupport {
-
- private boolean debugBeforeMethodCalled;
- private boolean debugAfterMethodCalled;
-
- // override this method, and return the location of our Blueprint XML file
to be used for testing
- @Override
- protected String getBlueprintDescriptor() {
- return "org/apache/camel/test/blueprint/camelContext.xml";
- }
-
- // here we have regular JUnit @Test method
- @Test
- public void testRoute() throws Exception {
-
- // set mock expectations
- getMockEndpoint("mock:a").expectedMessageCount(1);
-
- // send a message
- template.sendBody("direct:start", "World");
-
- // assert mocks
- assertMockEndpointsSatisfied();
-
- // assert on the debugBefore/debugAfter methods below being called as
we've enabled the debugger
- assertTrue(debugBeforeMethodCalled);
- assertTrue(debugAfterMethodCalled);
- }
-
- @Override
- public boolean isUseDebugger() {
- // must enable debugger
- return true;
- }
-
- @Override
- protected void debugBefore(Exchange exchange, org.apache.camel.Processor
processor, ProcessorDefinition<?> definition, String id, String label) {
- log.info("Before " + definition + " with body " +
exchange.getIn().getBody());
- debugBeforeMethodCalled = true;
- }
-
- @Override
- protected void debugAfter(Exchange exchange, org.apache.camel.Processor
processor, ProcessorDefinition<?> definition, String id, String label,
long timeTaken) {
- log.info("After " + definition + " with body " +
exchange.getIn().getBody());
- debugAfterMethodCalled = true;
- }
-}
-// end::example[]
-]]></script>
-</div></div>Also notice the use of
<strong><code>getBlueprintDescriptors</code></strong> to indicate that by
default we should look for the <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml"><code>camelContext.xml</code>
in the package</a> to configure the test case which looks like this:<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[
-<!-- tag::example[] -->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
-
- <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
-
- <route>
- <from uri="direct:start"/>
- <transform>
- <simple>Hello ${body}</simple>
- </transform>
- <to uri="mock:a"/>
- </route>
-
- </camelContext>
-
-</blueprint>
-<!-- end::example[] -->
-]]></script>
-</div></div><h3 id="Testing-TestingEndpoints">Testing Endpoints</h3><p>Camel
provides a number of endpoints which can make testing easier.</p><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>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="dataset.html">DataSet</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>For load & soak testing this endpoint provides a
way to create huge numbers of messages for sending to <a shape="rect"
href="components.html">Components</a> and asserting that they are consumed
correctly</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" href="mock.html">Mock</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>For testing routes and
mediation rules using mocks and allowing assertions to be added to an
endpoint</p
></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><a
>shape="rect" href="test.html">Test</a></p></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p>Creates a <a shape="rect" href="mock.html">Mock</a>
>endpoint which expects to receive all the message bodies that could be polled
>from the given underlying endpoint</p></td></tr></tbody></table></div><p>The
>main endpoint is the <a shape="rect" href="mock.html">Mock</a> endpoint which
>allows expectations to be added to different endpoints; you can then run your
>tests and assert that your expectations are met at the end.</p><h3
>id="Testing-Stubbingoutphysicaltransporttechnologies">Stubbing out physical
>transport technologies</h3><p>If you wish to test out a route but want to
>avoid actually using a real physical transport (for example to unit test a
>transformation route rather than performing a full integration test) then the
>following endpoints can be useful.</p><div class="table-wrap"><table
>class="confluenceTable"><t
body><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th
colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="direct.html">Direct</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Direct invocation of the consumer from the producer so
that single threaded (non-SEDA) in VM invocation is performed which can be
useful to mock out physical transports</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="seda.html">SEDA</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Delivers messages asynchronously to consumers via a <a
shape="rect" class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/BlockingQueue.html"
rel="nofollow">java.util.concurrent.BlockingQueue</a> which is good for
testing asynchronous transports</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceT
d"><p><a shape="rect" href="stub.html">Stub</a></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Works like <a shape="rect"
href="seda.html">SEDA</a> but does not validate the endpoint URI, which makes
stubbing much easier.</p></td></tr></tbody></table></div><h3
id="Testing-Testingexistingroutes">Testing existing routes</h3><p>Camel
provides some features to aid during testing of existing routes where you
cannot or will not use <a shape="rect" href="mock.html">Mock</a> etc. For
example you may have a production ready route which you want to test with some
3rd party API which sends messages into this route.</p><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>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="notifybuilder.html">NotifyBuilder</a></p></td><td colspan="1" rowspan="1"
class="co
nfluenceTd"><p>Allows you to be notified when a certain condition has
occurred. For example when the route has completed five messages. You can build
complex expressions to match your criteria when to be
notified.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect"
href="advicewith.html">AdviceWith</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Allows you to <strong>advice</strong> or
<strong>enhance</strong> an existing route using a <a shape="rect"
href="routebuilder.html">RouteBuilder</a> style. For example you can add
interceptors to intercept sending outgoing messages to assert those messages
are as expected.</p></td></tr></tbody></table></div></div>
+<div class="wiki-content maincontent"><h2
id="Testing-Testing">Testing</h2><p>Testing is a crucial activity in any piece
of software development or integration. Typically Camel Riders use various
different <a shape="rect" href="components.html">technologies</a> wired
together in a variety of <a shape="rect"
href="enterprise-integration-patterns.html">patterns</a> with different <a
shape="rect" href="languages.html">expression languages</a> together with
different forms of <a shape="rect" href="bean-integration.html">Bean
Integration</a> and <a shape="rect" href="dependency-injection.html">Dependency
Injection</a> so its very easy for things to go wrong! <img class="emoticon
emoticon-smile"
src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/smile.png"
data-emoticon-name="smile" alt="(smile)"> . Testing is the crucial weapon to
ensure that things work as you would expect.</p><p>Camel is a Java library so
you can ea
sily wire up tests in whatever unit testing framework you use (JUnit 3.x
(deprecated), 4.x, or TestNG). However the Camel project has tried to make the
testing of Camel as easy and powerful as possible so we have introduced the
following features.</p><h3 id="Testing-TestingMechanisms">Testing
Mechanisms</h3><p>The following mechanisms are supported:</p><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>Component</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="camel-test.html">Camel Test</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-test</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Is a standalone Java library letting you
easily create Camel test cases using a single Java class for all your
configuration and routing without using <a shape="rect"
href="cdi.html">CDI</a>, <a shape="rect" href="spring.html">Spring</a> or <a
shape="rect" href="guice.html">Guice</a> for <a shape="rect"
href="dependency-injection.html">Dependency Injection</a> which does not
require an in-depth knowledge of Spring + Spring Test or Guice.  Supports
JUnit 3.x (deprecated) and JUnit 4.x based tests.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><a shape="rect"
href="cdi-testing.html">CDI Testing</a></td><td colspan="1" rowspan="1"
class="confluenceTd"><code>camel-test-cdi</code></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Provides a JUnit 4 runner that bootstraps a
test environment using CDI so that you don't have to be familiar with any CDI
testing frameworks and can concentrate on the testing logic of your Camel CDI
applications. Testing frameworks like <a shape="rect"
class="external-link" href="http://arquillian.org/" rel="nofollow">Arquillian
</a> or <a shape="rect" class="external-link"
href="https://ops4j1.jira.com/wiki/display/PAXEXAM4" rel="nofollow">PAX
Exam</a>, can be used for more advanced test cases, where you need to configure
your system under test in a very fine-grained way or target specific CDI
containers.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" href="spring-testing.html">Spring
Testing</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-test-spring</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Supports JUnit 3.x (deprecated) or JUnit
4.x based tests that bootstrap a test environment using Spring without needing
to be familiar with Spring Test. The plain JUnit 3.x/4.x based tests work very
similar to the test support classes in
<strong><code>camel-test</code></strong>.</p><p>Also supports Spring Test based
tests that use the declarative style of test configuration and injection common
in Spring Test. The Spri
ng Test based tests provide feature parity with the plain JUnit 3.x/4.x based
testing approach.</p><p><strong>Note</strong>:
<strong><code>camel-test-spring</code></strong> is a new component from
<strong>Camel 2.10</strong>. For older Camel release use
<strong><code>camel-test</code></strong> which has built-in <a shape="rect"
href="spring-testing.html">Spring Testing</a>.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="blueprint-testing.html">Blueprint Testing</a></p></td><td colspan="1"
rowspan="1"
class="confluenceTd"><p><code>camel-test-blueprint</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong>
Provides the ability to do unit testing on blueprint
configurations</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" href="guice.html">Guice</a></p></td><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-guice</code></p></td><td colspan="1"
rowspan="1
" class="confluenceTd"><p><span style="color:
rgb(255,0,0);"><strong>Deprecated</strong></span></p><p>Uses <a shape="rect"
href="guice.html">Guice</a> to dependency inject your test
classes</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>Camel TestNG</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>camel-testng</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><span style="color:
rgb(255,0,0);"><strong>Deprecated</strong></span></p><p>Supports plain TestNG
based tests with or without <a shape="rect"
href="cdi.html">CDI</a>, <a shape="rect"
href="spring.html">Spring</a> or <a shape="rect"
href="guice.html">Guice</a> for <a shape="rect"
href="dependency-injection.html">Dependency Injection</a> which does not
require an in-depth knowledge of CDI, Spring + Spring Test or Guice.
 </p><p>From <strong>Camel 2.10</strong>: this component supports Spring
Test based tests that use the declarati
ve style of test configuration and injection common in Spring Test and
described in more detail under <a shape="rect"
href="spring-testing.html">Spring
Testing</a>.</p></td></tr></tbody></table></div><p>In all approaches the test
classes look pretty much the same in that they all reuse the <a shape="rect"
href="bean-integration.html">Camel binding and injection
annotations</a>.</p><h4 id="Testing-CamelTestExample">Camel Test
Example</h4><p>Here is the <a shape="rect" href="camel-test.html">Camel
Test</a> <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java">example</a>:<plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java}</plain-text-body>Notice
how it derives from the Camel helper class
<strong><code>CamelTestSupport</code></strong> but has no CDI, Spring or Guice
dependency
injection configuration but instead overrides the
<strong><code>createRouteBuilder()</code></strong> method.</p><h4
id="Testing-CDITestExample">CDI Test Example</h4><p>Here is the <a shape="rect"
href="cdi-testing.html">CDI Testing</a> <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java">example</a>:<plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java}</plain-text-body>You
can find more testing patterns illustrated in the
<strong><code>camel-example-cdi-test</code></strong> example and the test
classes that come with it.</p><h4
id="Testing-SpringTestwithXMLConfigExample">Spring Test with XML Config
Example</h4><p>Here is the <a shape="rect" href="spring-testing.html">Spring
Testing</a> <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trun
k/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java">example
using XML
Config</a>:<plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java}</plain-text-body>Notice
that we use <strong><code>@DirtiesContext</code></strong> on the test methods
to force <a shape="rect" href="spring-testing.html">Spring Testing</a> to
automatically reload the <code><a shape="rect"
href="camelcontext.html">CamelContext</a></code> after each test method - this
ensures that the tests don't clash with each other, e.g., one test method
sending to an endpoint that is then reused in another test method.</p><p>Also
note the use of <strong><code>@ContextConfiguration</code></strong> to indicate
that by default we should look for the <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
/patterns/FilterTest-context.xml"><code>FilterTest-context.xml</code> on the
classpath</a> to configure the test case which looks like
this:<plain-text-body>{snippet:lang=xml|id=example|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml}</plain-text-body></p><h4
id="Testing-SpringTestwithJavaConfigExample">Spring Test with Java Config
Example</h4><p>Here is the <a shape="rect" href="spring-testing.html">Spring
Testing</a> <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java">example
using Java Config</a>.</p><p>For more information see <a shape="rect"
href="spring-java-config.html">Spring Java
Config</a>.<plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java}</pla
in-text-body>This is similar to the XML Config example above except that there
is no XML file and instead the nested
<strong><code>ContextConfig</code></strong> class does all of the
configuration; so your entire test case is contained in a single Java class. We
currently have to reference by class name this class in the
<strong><code>@ContextConfiguration</code></strong> which is a bit ugly. Please
vote for <a shape="rect" class="external-link"
href="http://jira.springframework.org/browse/SJC-238"
rel="nofollow">SJC-238</a> to address this and make Spring Test work more
cleanly with Spring JavaConfig.</p><p>Its totally optional but for
the <strong><code>ContextConfig</code></strong> implementation we derive
from <strong><code>SingleRouteCamelConfiguration</code></strong> which is a
helper Spring Java Config class which will configure the
<strong><code>CamelContext</code></strong> for us and then register the
<strong><code>RouteBuilder</code></strong> we create.</p><p>Since <st
rong>Camel 2.11.0</strong> you can use the
<strong><code>CamelSpringJUnit4ClassRunner</code></strong> with
<strong><code>CamelSpringDelegatingTestContextLoader</code></strong> like <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java">example
using Java Config with
<code>CamelSpringJUnit4ClassRunner</code></a>:<plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java}</plain-text-body></p><h4
id="Testing-SpringTestwithXMLConfigandDeclarativeConfigurationExample">Spring
Test with XML Config and Declarative Configuration Example</h4><p>Here is a
Camel test support enhanced <a shape="rect"
href="spring-testing.html">Spring Testing</a> <a shape="rect"
class="external-l
ink"
href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringJUnit4ClassRunnerPlainTest.java">example
using XML Config and pure Spring Test based configuration of the Camel
Context</a>:<plain-text-body>{snippet:lang=java|id=e1|url=camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringJUnit4ClassRunnerPlainTest.java}</plain-text-body>Notice
how a custom test runner is used with
the <strong><code>@RunWith</code></strong> annotation to support the
features of <strong><code>CamelTestSupport</code></strong> through
annotations on the test class. See <a shape="rect"
href="spring-testing.html">Spring Testing</a> for a list of annotations
you can use in your tests.</p><h4 id="Testing-BlueprintTest">Blueprint
Test</h4><p>Here is the <a shape="rect" href="blueprint-testing.html">Blueprint
Testing</a> <a shape="rect" class="external-link" href="ht
tp://svn.apache.org/repos/asf/camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java">example
using XML
Config</a>:<plain-text-body>{snippet:lang=java|id=example|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java}</plain-text-body>Also
notice the use of <strong><code>getBlueprintDescriptors</code></strong> to
indicate that by default we should look for the <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml"><code>camelContext.xml</code>
in the package</a> to configure the test case which looks like
this:<plain-text-body>{snippet:lang=xml|id=example|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml}</plain-text-body></p><h3
id="Testing-TestingEndpoints">Testing
Endpoints</h3><p>Camel provides a number of endpoints which can make testing
easier.</p><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>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="dataset.html">DataSet</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>For load & soak testing this endpoint provides a
way to create huge numbers of messages for sending to <a shape="rect"
href="components.html">Components</a> and asserting that they are consumed
correctly</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" href="mock.html">Mock</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>For testing routes and
mediation rules using mocks and allowing assertions to be added to an
endpoint</p></td></tr><tr><td colspan="1" rowspan="1" class="con
fluenceTd"><p><a shape="rect" href="test.html">Test</a></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Creates a <a shape="rect"
href="mock.html">Mock</a> endpoint which expects to receive all the message
bodies that could be polled from the given underlying
endpoint</p></td></tr></tbody></table></div><p>The main endpoint is the <a
shape="rect" href="mock.html">Mock</a> endpoint which allows expectations to be
added to different endpoints; you can then run your tests and assert that your
expectations are met at the end.</p><h3
id="Testing-Stubbingoutphysicaltransporttechnologies">Stubbing out physical
transport technologies</h3><p>If you wish to test out a route but want to avoid
actually using a real physical transport (for example to unit test a
transformation route rather than performing a full integration test) then the
following endpoints can be useful.</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenc
eTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="direct.html">Direct</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Direct invocation of the consumer from the producer so
that single threaded (non-SEDA) in VM invocation is performed which can be
useful to mock out physical transports</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="seda.html">SEDA</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Delivers messages asynchronously to consumers via a <a
shape="rect" class="external-link"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/BlockingQueue.html"
rel="nofollow">java.util.concurrent.BlockingQueue</a> which is good for
testing asynchronous transports</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect" href="stub.html">Stub</a></p></
td><td colspan="1" rowspan="1" class="confluenceTd"><p>Works like <a
shape="rect" href="seda.html">SEDA</a> but does not validate the endpoint URI,
which makes stubbing much easier.</p></td></tr></tbody></table></div><h3
id="Testing-Testingexistingroutes">Testing existing routes</h3><p>Camel
provides some features to aid during testing of existing routes where you
cannot or will not use <a shape="rect" href="mock.html">Mock</a> etc. For
example you may have a production ready route which you want to test with some
3rd party API which sends messages into this route.</p><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>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><a shape="rect"
href="notifybuilder.html">NotifyBuilder</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Allows you to be notified when a certa
in condition has occurred. For example when the route has completed five
messages. You can build complex expressions to match your criteria when to be
notified.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><a shape="rect"
href="advicewith.html">AdviceWith</a></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Allows you to <strong>advice</strong> or
<strong>enhance</strong> an existing route using a <a shape="rect"
href="routebuilder.html">RouteBuilder</a> style. For example you can add
interceptors to intercept sending outgoing messages to assert those messages
are as expected.</p></td></tr></tbody></table></div></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/throttler.html
==============================================================================
--- websites/production/camel/content/throttler.html (original)
+++ websites/production/camel/content/throttler.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: Throttler
@@ -86,57 +75,11 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h3
id="Throttler-Throttler">Throttler</h3><p>The Throttler Pattern allows you to
ensure that a specific endpoint does not get overloaded, or that we don't
exceed an agreed SLA with some external service.</p><h3
id="Throttler-Options">Options</h3><div class="confluenceTableSmall">
+<div class="wiki-content maincontent"><h3
id="Throttler-Throttler">Throttler</h3><p>The Throttler Pattern allows you to
ensure that a specific endpoint does not get overloaded, or that we don't
exceed an agreed SLA with some external service.</p><h3
id="Throttler-Options">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body>
<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> Default Value </p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p> Description </p></th></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>
<code>maximumRequestsPerPeriod</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> Maximum number of requests per period to throttle.
This option must be provided as a positive number. Notice, in the XML DSL, from
<strong>Camel 2.8</strong> onwards this option is configured using an <a
shape="rect" href="expression.html">Expression</a> instead of an attribute.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>timePeriodMillis</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>1000</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> The time period in milliseconds, in
which the throttler will allow at most <code>maximumRequestsPerPeriod</code>
number of messages. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>asyncDelayed</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>false</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <strong>Camel 2.4:</strong> If
enabled then any messages which is delayed happens asynchronously using a
scheduled thread pool. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>executorServiceRef</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <strong>Camel 2.4:</strong> Refers to a
custom <a shape="rect" href="threading-model.html">Thread Pool</a> to be used
if <code>asyncDelay</code> has been enabled. </p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenc
eTd"><p> <code>callerRunsWhenRejected</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>true</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <strong>Camel 2.4:</strong> Is used if
<code>asyncDelayed</code> was enabled. This controls if the caller thread
should execute the task if the thread pool rejected the task.
</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>
<code>rejectExecution</code> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>false</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <strong>Camel 2.14:</strong> If this
option is true, throttler throws a ThrottlerRejectExecutionException when the
request rate exceeds the limit. </p></td></tr></tbody></table></div>
-</div>
-
-
-<h3 id="Throttler-Examples">Examples</h3><p><strong>Using the <a shape="rect"
href="fluent-builders.html">Fluent Builders</a></strong></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:a").throttle(3).timePeriodMillis(1000).to("log:result",
"mock:result");
-]]></script>
-</div></div><p>So the above example will throttle messages all messages
received on <strong>seda:a</strong> before being sent to
<strong>mock:result</strong> ensuring that a maximum of 3 messages are sent in
any 10 second window.</p><p>Note that since <code>timePeriodMillis</code>
defaults to 1000 milliseconds, just setting the
<code>maximumRequestsPerPeriod</code> has the effect of setting the maximum
number of requests per second. So to throttle requests at 100 requests per
second between two endpoints, it would look more like this...</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:a").throttle(100).to("seda:b");
-]]></script>
-</div></div><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/ThrottlerTest.java?view=markup">junit
test case</a></p><p><strong>Using the <a shape="rect"
href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p><h4
id="Throttler-Camel2.7.xorolder">Camel 2.7.x or older</h4><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="seda:a" />
- <throttle maximumRequestsPerPeriod="3"
timePeriodMillis="10000">
- <to uri="mock:result" />
- </throttle>
-</route>
-]]></script>
-</div></div><h4 id="Throttler-Camel2.8onwards">Camel 2.8 onwards</h4><p>In
Camel 2.8 onwards you must set the maximum period as an <a shape="rect"
href="expression.html">Expression</a> as shown below where we use a <a
shape="rect" href="constant.html">Constant</a> expression:</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="seda:a"/>
- <!-- throttle 3 messages per 1 sec -->
- <throttle timePeriodMillis="1000">
- <constant>3</constant>
- <to uri="log:result"/>
- <to uri="mock:result"/>
- </throttle>
-</route>
-]]></script>
-</div></div><h3
id="Throttler-Dynamicallychangingmaximumrequestsperperiod">Dynamically changing
maximum requests per period</h3><p><strong>Available as of Camel 2.8</strong>
<br clear="none"> Since we use an <a shape="rect"
href="expression.html">Expression</a> you can adjust this value at runtime, for
example you can provide a header with the value. At runtime Camel evaluates the
expression and converts the result to a <code>java.lang.Long</code> type. In
the example below we use a header from the message to determine the maximum
requests per period. If the header is absent, then the <a shape="rect"
href="throttler.html">Throttler</a> uses the old value. So that allows you to
only provide a header if the value is to be changed:</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="direct:expressionHeader"/>
- <throttle timePeriodMillis="500">
- <!-- use a header to determine how many messages to throttle per 0.5
sec -->
- <header>throttleValue</header>
- <to uri="log:result"/>
- <to uri="mock:result"/>
- </throttle>
-</route>
-]]></script>
-</div></div><h3 id="Throttler-Asynchronousdelaying">Asynchronous
delaying</h3><p><strong>Available as of Camel 2.4</strong></p><p>You can let
the <a shape="rect" href="throttler.html">Throttler</a> use non blocking
asynchronous delaying, which means Camel will use a scheduler to schedule a
task to be executed in the future. The task will then continue routing. This
allows the caller thread to not block and be able to service other messages,
etc.</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:a").throttle(100).asyncDelayed().to("seda:b");
-]]></script>
-</div></div><p></p><h4 id="Throttler-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>
+</rich-text-body><h3 id="Throttler-Examples">Examples</h3><p><strong>Using the
<a shape="rect" href="fluent-builders.html">Fluent
Builders</a></strong></p><plain-text-body>{snippet:id=ex|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ThrottlerTest.java}</plain-text-body><p>So
the above example will throttle messages all messages received on
<strong>seda:a</strong> before being sent to <strong>mock:result</strong>
ensuring that a maximum of 3 messages are sent in any 10 second
window.</p><p>Note that since <code>timePeriodMillis</code> defaults to 1000
milliseconds, just setting the <code>maximumRequestsPerPeriod</code> has the
effect of setting the maximum number of requests per second. So to throttle
requests at 100 requests per second between two endpoints, it would look more
like this...</p><plain-text-body>from("seda:a").throttle(100).to("seda:b");
+</plain-text-body><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/ThrottlerTest.java?view=markup">junit
test case</a></p><p><strong>Using the <a shape="rect"
href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p><h4
id="Throttler-Camel2.7.xorolder">Camel 2.7.x or
older</h4><plain-text-body>{snippet:id=example|lang=xml|url=camel/tags/camel-2.7.0/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/throttler.xml}</plain-text-body><h4
id="Throttler-Camel2.8onwards">Camel 2.8 onwards</h4><p>In Camel 2.8 onwards
you must set the maximum period as an <a shape="rect"
href="expression.html">Expression</a> as shown below where we use a <a
shape="rect" href="constant.html">Constant</a>
expression:</p><plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/re
sources/org/apache/camel/spring/processor/throttler.xml}</plain-text-body><h3
id="Throttler-Dynamicallychangingmaximumrequestsperperiod">Dynamically changing
maximum requests per period</h3><p><strong>Available as of Camel 2.8</strong>
<br clear="none"> Since we use an <a shape="rect"
href="expression.html">Expression</a> you can adjust this value at runtime, for
example you can provide a header with the value. At runtime Camel evaluates the
expression and converts the result to a <code>java.lang.Long</code> type. In
the example below we use a header from the message to determine the maximum
requests per period. If the header is absent, then the <a shape="rect"
href="throttler.html">Throttler</a> uses the old value. So that allows you to
only provide a header if the value is to be
changed:</p><plain-text-body>{snippet:id=e2|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/throttler.xml}</plain-text-body><h3
id="Throttler-Asynchron
ousdelaying">Asynchronous delaying</h3><p><strong>Available as of Camel
2.4</strong></p><p>You can let the <a shape="rect"
href="throttler.html">Throttler</a> use non blocking asynchronous delaying,
which means Camel will use a scheduler to schedule a task to be executed in the
future. The task will then continue routing. This allows the caller thread to
not block and be able to service other messages,
etc.</p><plain-text-body>from("seda:a").throttle(100).asyncDelayed().to("seda:b");
+</plain-text-body><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">