Modified: websites/production/camel/content/debugger.html
==============================================================================
--- websites/production/camel/content/debugger.html (original)
+++ websites/production/camel/content/debugger.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: Debugger
@@ -86,42 +75,8 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="Debugger-Debugger">Debugger</h2><p><strong>Available as of Camel
2.6</strong></p><p>Camel <a shape="rect" href="debugger.html">Debugger</a> is
much related to <a shape="rect" href="tracer.html">Tracer</a>, in fact they are
sisters. Debugger is a enhanced tracer with a debugger framework so that
tooling can be developed to easily monitor Camel routes, trace messages and set
breakpoints at points in a route etc.</p><div
class="confluence-information-macro confluence-information-macro-tip"><span
class="aui-icon aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>There is also a <a shape="rect"
href="backlogdebugger.html">BacklogDebugger</a> which allows to debug from JMX,
and 3rd party tooling.</p></div></div><h3 id="Debugger-AbouttheDebugger">About
the Debugger</h3><p>The Debugger allows tooling or the likes to attach
breakpoints which is being invoked when <a shap
e="rect" href="exchange.html">Exchange</a>s are being routed.</p><h3
id="Debugger-DefaultImplementation">Default Implementation</h3><p>Camel
provides a default implementation
<strong><code>org.apache.camel.impl.DefaultDebugger</code></strong> which you
can set on the <strong><code>CamelContext</code></strong> using the
<strong><code>setDebugger</code></strong> method. Likewise you can get hold of
the <a shape="rect" href="debugger.html">Debugger</a> using the
<strong><code>getDebugger</code></strong> method on
<strong><code>CamelContext</code></strong>.</p><p>The
<strong><code>org.apache.camel.spi.Debugger</code></strong> has methods to
attach and remove breakpoints. And to suspend/resume all breakpoints etc. You
can also attach a condition to the breakpoint so it only reacts if the
condition matches.</p><h3
id="Debugger-DebuggingCamelRoutesUsingcamel-test">Debugging Camel Routes Using
<code>camel-test</code></h3><p>If you are developing unit tests using the
<strong><code>camel-test
</code></strong> component, then the <a shape="rect"
href="debugger.html">Debugger</a> comes out of the box. From <strong>Camel
2.9</strong>: you would need to explicit enable the debugger, by overriding
<strong><code>isUseDebugger()</code></strong> method and return
<strong><code>true</code></strong>.</p><h4
id="Debugger-Example">Example</h4><p>In this unit test</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[public class DebugTest extends
CamelTestSupport
-]]></script>
-</div></div><p>We want to debug the following route:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-@Override
-protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- // this is the route we want to debug
- from("direct:start")
- .to("mock:a")
- .transform(body().prepend("Hello "))
- .to("mock:b");
- }
- };
-}
-]]></script>
-</div></div>Which can easily done by overriding the
<strong><code>debugBefore</code></strong> method as shown:<div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-@Override
-public boolean isUseDebugger() {
- // must enable debugger
- return true;
-}
-
-@Override
-protected void debugBefore(Exchange exchange, Processor processor,
- ProcessorDefinition<?> definition, String id,
String shortName) {
- // this method is invoked before we are about to enter the given processor
- // from your Java editor you can just add a breakpoint in the code line
below
- log.info("Before " + definition + " with body " +
exchange.getIn().getBody());
-}
-]]></script>
-</div></div>Then from your Java editor just add a breakpoint inside the
<strong><code>debugBefore</code></strong> method. Then fire up the unit test
and wait for the Java editor to hit the breakpoint. Then you can inspect the <a
shape="rect" href="exchange.html">Exchange</a> during debugging while it
advances during routing. The <strong><code>ProcessorDefinition</code></strong>
and the <strong><code>id</code></strong> and
<strong><code>shortName</code></strong> parameters is all information which
tells you where in the route the breakpoint was hit.<div
class="confluence-information-macro confluence-information-macro-tip"><span
class="aui-icon aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>There is also a
<strong><code>debugAfter</code></strong> method which is invoked after the
processor has been invoked. This allows you to <em>see</em> what happens to the
<a shape="rect" href="exchange.html">Exchange</
a> right after it has invoked a processor in the route.</p></div></div><p>The
screenshot below shows the <a shape="rect" href="debugger.html">Debugger</a> in
action. The IDE (IDEA) has hit the breakpoint and we can inspect the
parameters. Notice how we can see that the message is to be send to
the <strong><code>mock:a</code></strong> endpoint:</p><p><span
class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image"
src="debugger.data/debug.png"
data-image-src="/confluence/download/attachments/86210/debug.png?version=1&modificationDate=1288586116000&api=v2"
data-unresolved-comment-count="0" data-linked-resource-id="24346680"
data-linked-resource-version="1" data-linked-resource-type="attachment"
data-linked-resource-default-alias="debug.png"
data-base-url="https://cwiki.apache.org/confluence"
data-linked-resource-content-type="image/png"
data-linked-resource-container-id="86210"
data-linked-resource-container-version="38"></span></p><h3 id="Debugger-Se
eAlso">See Also</h3><ul class="alternate"><li><a shape="rect"
href="tracer.html">Tracer</a></li><li><a shape="rect"
href="backlogdebugger.html">BacklogDebugger</a></li></ul></div>
+<div class="wiki-content maincontent"><h2
id="Debugger-Debugger">Debugger</h2><p><strong>Available as of Camel
2.6</strong></p><p>Camel <a shape="rect" href="debugger.html">Debugger</a> is
much related to <a shape="rect" href="tracer.html">Tracer</a>, in fact they are
sisters. Debugger is a enhanced tracer with a debugger framework so that
tooling can be developed to easily monitor Camel routes, trace messages and set
breakpoints at points in a route etc.</p><rich-text-body><p>There is also a <a
shape="rect" href="backlogdebugger.html">BacklogDebugger</a> which allows to
debug from JMX, and 3rd party tooling.</p></rich-text-body><h3
id="Debugger-AbouttheDebugger">About the Debugger</h3><p>The Debugger allows
tooling or the likes to attach breakpoints which is being invoked when <a
shape="rect" href="exchange.html">Exchange</a>s are being routed.</p><h3
id="Debugger-DefaultImplementation">Default Implementation</h3><p>Camel
provides a default implementation <strong><code>org.apache.c
amel.impl.DefaultDebugger</code></strong> which you can set on the
<strong><code>CamelContext</code></strong> using the
<strong><code>setDebugger</code></strong> method. Likewise you can get hold of
the <a shape="rect" href="debugger.html">Debugger</a> using the
<strong><code>getDebugger</code></strong> method on
<strong><code>CamelContext</code></strong>.</p><p>The
<strong><code>org.apache.camel.spi.Debugger</code></strong> has methods to
attach and remove breakpoints. And to suspend/resume all breakpoints etc. You
can also attach a condition to the breakpoint so it only reacts if the
condition matches.</p><h3
id="Debugger-DebuggingCamelRoutesUsingcamel-test">Debugging Camel Routes Using
<code>camel-test</code></h3><p>If you are developing unit tests using the
<strong><code>camel-test</code></strong> component, then the <a shape="rect"
href="debugger.html">Debugger</a> comes out of the box. From <strong>Camel
2.9</strong>: you would need to explicit enable the debugger, by overridi
ng <strong><code>isUseDebugger()</code></strong> method and return
<strong><code>true</code></strong>.</p><h4
id="Debugger-Example">Example</h4><p>In this unit
test</p><plain-text-body>public class DebugTest extends CamelTestSupport
+</plain-text-body><p>We want to debug the following
route:<plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugTest.java}</plain-text-body>Which
can easily done by overriding the <strong><code>debugBefore</code></strong>
method as
shown:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/patterns/DebugTest.java}</plain-text-body>Then
from your Java editor just add a breakpoint inside the
<strong><code>debugBefore</code></strong> method. Then fire up the unit test
and wait for the Java editor to hit the breakpoint. Then you can inspect the <a
shape="rect" href="exchange.html">Exchange</a> during debugging while it
advances during routing. The <strong><code>ProcessorDefinition</code></strong>
and the <strong><code>id</code></strong> and
<strong><code>shortName</code></strong> parameters is all information which
tells you where in the route the br
eakpoint was hit.</p><rich-text-body><p>There is also a
<strong><code>debugAfter</code></strong> method which is invoked after the
processor has been invoked. This allows you to <em>see</em> what happens to the
<a shape="rect" href="exchange.html">Exchange</a> right after it has invoked a
processor in the route.</p></rich-text-body><p>The screenshot below shows the
<a shape="rect" href="debugger.html">Debugger</a> in action. The IDE (IDEA) has
hit the breakpoint and we can inspect the parameters. Notice how we can see
that the message is to be send to the <strong><code>mock:a</code></strong>
endpoint:</p><p><span class="confluence-embedded-file-wrapper"><img
class="confluence-embedded-image" src="debugger.data/debug.png"
data-image-src="/confluence/download/attachments/86210/debug.png?version=1&modificationDate=1288586116000&api=v2"
data-unresolved-comment-count="0" data-linked-resource-id="24346680"
data-linked-resource-version="1" data-linked-resource-type="attachment
" data-linked-resource-default-alias="debug.png"
data-base-url="https://cwiki.apache.org/confluence"
data-linked-resource-content-type="image/png"
data-linked-resource-container-id="86210"
data-linked-resource-container-version="39"></span></p><h3
id="Debugger-SeeAlso">See Also</h3><ul class="alternate"><li><a shape="rect"
href="tracer.html">Tracer</a></li><li><a shape="rect"
href="backlogdebugger.html">BacklogDebugger</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/delayer.html
==============================================================================
--- websites/production/camel/content/delayer.html (original)
+++ websites/production/camel/content/delayer.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: Delayer
@@ -86,92 +75,31 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h3
id="Delayer-Delayer">Delayer</h3><p>The Delayer Pattern allows you to delay the
delivery of messages to some destination.</p><div
class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The expression is a value in
millis to wait from the current time, so the expression should just be
<code>3000</code>.<br clear="none"> However you can use a long value for a
fixed value to indicate the delay in millis.<br clear="none"> See the Spring
DSL samples for Delayer.</p></div></div><div
class="confluence-information-macro confluence-information-macro-warning"><p
class="title">Using Delayer in Java DSL</p><span class="aui-icon aui-icon-small
aui-iconfont-error confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>See this ticket: <a shape="rect" cl
ass="external-link"
href="https://issues.apache.org/jira/browse/CAMEL-2654">https://issues.apache.org/jira/browse/CAMEL-2654</a></p></div></div><h3
id="Delayer-Options">Options</h3><div class="confluenceTableSmall">
+<div class="wiki-content maincontent"><h3
id="Delayer-Delayer">Delayer</h3><p>The Delayer Pattern allows you to delay the
delivery of messages to some destination.</p><parameter
ac:name="">Delayer</parameter><rich-text-body><p>The expression is a value in
millis to wait from the current time, so the expression should just be
<code>3000</code>.<br clear="none"> However you can use a long value for a
fixed value to indicate the delay in millis.<br clear="none"> See the Spring
DSL samples for Delayer.</p></rich-text-body><parameter ac:name="title">Using
Delayer in Java DSL</parameter><rich-text-body><p>See this ticket: <a
shape="rect" class="external-link"
href="https://issues.apache.org/jira/browse/CAMEL-2654">https://issues.apache.org/jira/browse/CAMEL-2654</a></p></rich-text-body><h3
id="Delayer-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>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 delayed
messages 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>asyncDel
ay</code> has been enabled. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><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></tbody></table></div>
-</div>
-
-
-<p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent
Builders</a></strong></p><p>The example below will delay all messages received
on <strong>seda:b</strong> 1 second before sending them to <strong><a
shape="rect" class="external-link" href="http://mockresult"
rel="nofollow">mock:result</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:b").delay(100).to("mock:result");
-]]></script>
-</div></div><p>You can just delay things a fixed amount of time from the point
at which the delayer receives the message. For example to delay things 2
seconds</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[delayer(2000)
-]]></script>
-</div></div><p>The above assume that the delivery order is maintained and that
the messages are delivered in delay order. If you want to reorder the messages
based on delivery time, you can use the <a shape="rect"
href="resequencer.html">Resequencer</a> with this pattern. For example</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("activemq:someQueue").resequencer(header("MyDeliveryTime")).delay("MyRedeliveryTime").to("activemq:aDelayedQueue");
-]]></script>
-</div></div><p>You can of course use many different <a shape="rect"
href="expression.html">Expression</a> languages such as <a shape="rect"
href="xpath.html">XPath</a>, <a shape="rect" href="xquery.html">XQuery</a>, <a
shape="rect" href="sql.html">SQL</a> or various <a shape="rect"
href="scripting-languages.html">Scripting Languages</a>. For example to delay
the message for the time period specified in the header, use the following
syntax:</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:someQueue").delay(header("delayValue")).to("activemq:aDelayedQueue");
-]]></script>
-</div></div><p>And to delay processing using the <a shape="rect"
href="simple.html">Simple</a> language you can use the following 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[from("activemq:someQueue").delay(simple("${body.delayProperty}")).to("activemq:aDelayedQueue");
-]]></script>
-</div></div><h4 id="Delayer-SpringDSL">Spring DSL</h4><p>The sample below
demonstrates the delay in Spring DSL:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<bean id="myDelayBean"
class="org.apache.camel.processor.MyDelayCalcBean"/>
-<bean id="exchangeAwareBean"
class="org.apache.camel.processor.ExchangeAwareDelayCalcBean"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="seda:a"/>
- <delay>
- <header>MyDelay</header>
- </delay>
- <to uri="mock:result"/>
- </route>
- <route>
- <from uri="seda:b"/>
- <delay>
- <constant>1000</constant>
- </delay>
- <to uri="mock:result"/>
- </route>
- <route>
- <from uri="seda:c"/>
- <delay>
- <method ref="myDelayBean"
method="delayMe"/>
- </delay>
- <to uri="mock:result"/>
- </route>
- <route>
- <from uri="seda:d"/>
- <delay>
- <method ref="exchangeAwareBean"
method="delayMe"/>
- </delay>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-]]></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/DelayerTest.java?view=markup">junit
test case</a></p><h3 id="Delayer-Asynchronousdelaying">Asynchronous
delaying</h3><p><strong>Available as of Camel 2.4</strong></p><p>You can let
the <a shape="rect" href="delayer.html">Delayer</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><h4 id="Delayer-FromJavaDSL">From Java DSL</h4><p>You use the
<code>asyncDelayed()</code> to enable the async behavior.</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:queue:foo").delay(1000).asyncDelayed().to("activemq:aDelayedQueue");
-]]></script>
-</div></div><h4 id="Delayer-FromSpringXML">From Spring XML</h4><p>You use the
<code>asyncDelayed="true"</code> attribute to enable the async
behavior.</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="activemq:queue:foo"/>
- <delay asyncDelayed="true">
+</rich-text-body><p><strong>Using the <a shape="rect"
href="fluent-builders.html">Fluent Builders</a></strong></p><p>The example
below will delay all messages received on <strong>seda:b</strong> 1 second
before sending them to <strong><a shape="rect" class="external-link"
href="http://mockresult"
rel="nofollow">mock:result</a></strong>.</p><plain-text-body>{snippet:id=ex2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DelayerTest.java}</plain-text-body><p>You
can just delay things a fixed amount of time from the point at which the
delayer receives the message. For example to delay things 2
seconds</p><plain-text-body>delayer(2000)
+</plain-text-body><p>The above assume that the delivery order is maintained
and that the messages are delivered in delay order. If you want to reorder the
messages based on delivery time, you can use the <a shape="rect"
href="resequencer.html">Resequencer</a> with this pattern. For
example</p><plain-text-body>from("activemq:someQueue").resequencer(header("MyDeliveryTime")).delay("MyRedeliveryTime").to("activemq:aDelayedQueue");
+</plain-text-body><p>You can of course use many different <a shape="rect"
href="expression.html">Expression</a> languages such as <a shape="rect"
href="xpath.html">XPath</a>, <a shape="rect" href="xquery.html">XQuery</a>, <a
shape="rect" href="sql.html">SQL</a> or various <a shape="rect"
href="scripting-languages.html">Scripting Languages</a>. For example to delay
the message for the time period specified in the header, use the following
syntax:</p><plain-text-body>from("activemq:someQueue").delay(header("delayValue")).to("activemq:aDelayedQueue");
+</plain-text-body><p>And to delay processing using the <a shape="rect"
href="simple.html">Simple</a> language you can use the following
DSL:</p><plain-text-body>from("activemq:someQueue").delay(simple("${body.delayProperty}")).to("activemq:aDelayedQueue");
+</plain-text-body><h4 id="Delayer-SpringDSL">Spring DSL</h4><p>The sample
below demonstrates the delay in Spring
DSL:</p><plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml}</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/DelayerTest.java?view=markup">junit
test case</a></p><h3 id="Delayer-Asynchronousdelaying">Asynchronous
delaying</h3><p><strong>Available as of Camel 2.4</strong></p><p>You can let
the <a shape="rect" href="delayer.html">Delayer</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><h4 id="Delaye
r-FromJavaDSL">From Java DSL</h4><p>You use the <code>asyncDelayed()</code> to
enable the async
behavior.</p><plain-text-body>from("activemq:queue:foo").delay(1000).asyncDelayed().to("activemq:aDelayedQueue");
+</plain-text-body><h4 id="Delayer-FromSpringXML">From Spring XML</h4><p>You
use the <code>asyncDelayed="true"</code> attribute to enable the async
behavior.</p><parameter ac:name="">xml</parameter><plain-text-body><route>
+ <from uri="activemq:queue:foo"/>
+ <delay asyncDelayed="true">
<constant>1000</constant>
</delay>
- <to uri="activemq:aDealyedQueue"/>
+ <to uri="activemq:aDealyedQueue"/>
</route>
-]]></script>
-</div></div><h3 id="Delayer-Creatingacustomdelay">Creating a custom
delay</h3><p>You can use an expression to determine when to send a message
using something 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("activemq:foo").
- delay().method("someBean", "computeDelay").
- to("activemq:bar");
-]]></script>
-</div></div><p>then the bean would look 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[public class SomeBean {
+</plain-text-body><h3 id="Delayer-Creatingacustomdelay">Creating a custom
delay</h3><p>You can use an expression to determine when to send a message
using something like this</p><plain-text-body>from("activemq:foo").
+ delay().method("someBean", "computeDelay").
+ to("activemq:bar");
+</plain-text-body><p>then the bean would look like
this...</p><plain-text-body>public class SomeBean {
public long computeDelay() {
long delay = 0;
// use java code to compute a delay value in millis
return delay;
}
}
-]]></script>
-</div></div><p></p><h4 id="Delayer-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><h3
id="Delayer-SeeAlso">See Also</h3><ul><li><a shape="rect"
href="delay-interceptor.html">Delay Interceptor</a></li></ul></div>
+</plain-text-body><p><parameter ac:name=""><a shape="rect"
href="using-this-pattern.html">Using This Pattern</a></parameter></p><h3
id="Delayer-SeeAlso">See Also</h3><ul><li><a shape="rect"
href="delay-interceptor.html">Delay Interceptor</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/dynamic-router.html
==============================================================================
--- websites/production/camel/content/dynamic-router.html (original)
+++ websites/production/camel/content/dynamic-router.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: Dynamic Router
@@ -86,125 +75,27 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="DynamicRouter-DynamicRouter">Dynamic Router</h2><p>The <a shape="rect"
class="external-link"
href="http://www.enterpriseintegrationpatterns.com/DynamicRouter.html"
rel="nofollow">Dynamic Router</a> from the <a shape="rect"
href="enterprise-integration-patterns.html">EIP patterns</a> allows you to
route messages while avoiding the dependency of the router on all possible
destinations while maintaining its efficiency.</p><p><span
class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image
confluence-external-resource"
src="http://www.enterpriseintegrationpatterns.com/img/DynamicRouter.gif"
data-image-src="http://www.enterpriseintegrationpatterns.com/img/DynamicRouter.gif"></span></p><p>In
<strong>Camel 2.5</strong> we introduced a <code>dynamicRouter</code> in the
DSL which is like a dynamic <a shape="rect" href="routing-slip.html">Routing
Slip</a> which evaluates the slip <em>on-the-fly</em>.</p><div
class="confluence-i
nformation-macro confluence-information-macro-warning"><p
class="title">Beware</p><span class="aui-icon aui-icon-small aui-iconfont-error
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>You must ensure the expression
used for the <code>dynamicRouter</code> such as a bean, will return
<code>null</code> to indicate the end. Otherwise the <code>dynamicRouter</code>
will keep repeating endlessly.</p></div></div><h3
id="DynamicRouter-Options">Options</h3><div class="confluenceTableSmall">
+<div class="wiki-content maincontent"><h2
id="DynamicRouter-DynamicRouter">Dynamic Router</h2><p>The <a shape="rect"
class="external-link"
href="http://www.enterpriseintegrationpatterns.com/DynamicRouter.html"
rel="nofollow">Dynamic Router</a> from the <a shape="rect"
href="enterprise-integration-patterns.html">EIP patterns</a> allows you to
route messages while avoiding the dependency of the router on all possible
destinations while maintaining its efficiency.</p><p><span
class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image
confluence-external-resource"
src="http://www.enterpriseintegrationpatterns.com/img/DynamicRouter.gif"
data-image-src="http://www.enterpriseintegrationpatterns.com/img/DynamicRouter.gif"></span></p><p>In
<strong>Camel 2.5</strong> we introduced a <code>dynamicRouter</code> in the
DSL which is like a dynamic <a shape="rect" href="routing-slip.html">Routing
Slip</a> which evaluates the slip <em>on-the-fly</em>.</p><parameter
ac:name="titl
e">Beware</parameter><rich-text-body><p>You must ensure the expression used
for the <code>dynamicRouter</code> such as a bean, will return
<code>null</code> to indicate the end. Otherwise the <code>dynamicRouter</code>
will keep repeating endlessly.</p></rich-text-body><h3
id="DynamicRouter-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>uriDelimiter</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> <code>,</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Delimiter used if
the <a shape="rect" href="expression.html">Expression</a> returned multiple
endpoints. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>ignoreInvalidEndpoints</code> </p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> <code>false</code>
</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> If an endpoint
uri could not be resolved, should it be ignored. Otherwise Camel will thrown an
exception stating the endpoint uri is
not valid. </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p> <code>cacheSize</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <code>1000</code> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> <strong>Camel 2.13.1/2.12.4:</strong>
Allows to configure the cache size for the <code>ProducerCache</code> which
caches producers for reuse in the routing slip. Will by default use the default
cache size which is 1000. Setting the value to -1 allows to turn off the cache
all together. </p></td></tr></tbody></table></div>
-</div>
-
-
-<h3 id="DynamicRouter-DynamicRouterinCamel2.5onwards">Dynamic Router in Camel
2.5 onwards</h3><p>From Camel 2.5 the <a shape="rect"
href="dynamic-router.html">Dynamic Router</a> will set a property
(Exchange.SLIP_ENDPOINT) on the <a shape="rect"
href="exchange.html">Exchange</a> which contains the current endpoint as it
advanced though the slip. This allows you to know how far we have processed in
the slip. (It's a slip because the <a shape="rect"
href="dynamic-router.html">Dynamic Router</a> implementation is based on top of
<a shape="rect" href="routing-slip.html">Routing Slip</a>).</p><h4
id="DynamicRouter-JavaDSL">Java DSL</h4><p>In Java DSL you can use the
<code>dynamicRouter</code> 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[
-from("direct:start")
- // use a bean as the dynamic router
- .dynamicRouter(method(DynamicRouterTest.class, "slip"));
-]]></script>
-</div></div><p>Which will leverage a <a shape="rect" href="bean.html">Bean</a>
to compute the slip <em>on-the-fly</em>, which could be implemented 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[
-/**
- * Use this method to compute dynamic where we should route next.
- *
- * @param body the message body
- * @return endpoints to go, or <tt>null</tt> to indicate the end
- */
-public String slip(String body) {
- bodies.add(body);
- invoked++;
-
- if (invoked == 1) {
- return "mock:a";
- } else if (invoked == 2) {
- return "mock:b,mock:c";
- } else if (invoked == 3) {
- return "direct:foo";
- } else if (invoked == 4) {
- return "mock:result";
- }
+</rich-text-body><h3 id="DynamicRouter-DynamicRouterinCamel2.5onwards">Dynamic
Router in Camel 2.5 onwards</h3><p>From Camel 2.5 the <a shape="rect"
href="dynamic-router.html">Dynamic Router</a> will set a property
(Exchange.SLIP_ENDPOINT) on the <a shape="rect"
href="exchange.html">Exchange</a> which contains the current endpoint as it
advanced though the slip. This allows you to know how far we have processed in
the slip. (It's a slip because the <a shape="rect"
href="dynamic-router.html">Dynamic Router</a> implementation is based on top of
<a shape="rect" href="routing-slip.html">Routing Slip</a>).</p><h4
id="DynamicRouter-JavaDSL">Java DSL</h4><p>In Java DSL you can use the
<code>dynamicRouter</code> as shown
below:</p><plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DynamicRouterTest.java}</plain-text-body><p>Which
will leverage a <a shape="rect" href="bean.html">Bean</a> to compute the slip
<em>on-the-fly</em>, which
could be implemented as
follows:</p><plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DynamicRouterTest.java}</plain-text-body><p>Mind
that this example is only for show and tell. The current implementation is not
thread safe. You would have to store the state on the <a shape="rect"
href="exchange.html">Exchange</a>, to ensure thread safety, as shown
below:</p><plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DynamicRouterExchangePropertiesTest.java}</plain-text-body><p>You
could also store state as message headers, but they are not guaranteed to be
preserved during routing, where as properties on the <a shape="rect"
href="exchange.html">Exchange</a> are. Although there was a bug in the method
call expression, see the warning below.</p><parameter ac:name="title">Using
beans to store state</parameter><rich-text-body><p>Mind that in Camel 2.9.2 or
older, when using
a <a shape="rect" href="bean.html">Bean</a> the state is not propagated, so
you will have to use a <a shape="rect" href="processor.html">Processor</a>
instead. This is fixed in Camel 2.9.3 onwards.</p></rich-text-body><h4
id="DynamicRouter-SpringXML">Spring XML</h4><p>The same example in Spring XML
would
be:</p><plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDynamicRouterTest.xml}</plain-text-body><h4
id="DynamicRouter-@DynamicRouterannotation">@DynamicRouter
annotation</h4><p>You can also use the <code>@DynamicRouter</code> annotation,
for example the Camel 2.4 example below could be written as follows. The
<code>route</code> method would then be invoked repeatedly as the message is
processed dynamically. The idea is to return the next endpoint uri where to go.
Return <code>null</code> to indicate the end. You can return multiple endpoints
if you like, just as the <a shape="rect" href="routi
ng-slip.html">Routing Slip</a>, where each endpoint is separated by a
delimiter.</p><parameter ac:name="">java</parameter><plain-text-body>public
class MyDynamicRouter {
- // no more so return null
- return null;
-}
-]]></script>
-</div></div><p>Mind that this example is only for show and tell. The current
implementation is not thread safe. You would have to store the state on the <a
shape="rect" href="exchange.html">Exchange</a>, to ensure thread safety, 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[
-/**
- * Use this method to compute dynamic where we should route next.
- *
- * @param body the message body
- * @param properties the exchange properties where we can store state between
invocations
- * @return endpoints to go, or <tt>null</tt> to indicate the end
- */
-public String slip(String body, @ExchangeProperties Map<String, Object>
properties) {
- bodies.add(body);
-
- // get the state from the exchange properties and keep track how many times
- // we have been invoked
- int invoked = 0;
- Object current = properties.get("invoked");
- if (current != null) {
- invoked = Integer.valueOf(current.toString());
- }
- invoked++;
- // and store the state back on the properties
- properties.put("invoked", invoked);
-
- if (invoked == 1) {
- return "mock:a";
- } else if (invoked == 2) {
- return "mock:b,mock:c";
- } else if (invoked == 3) {
- return "direct:foo";
- } else if (invoked == 4) {
- return "mock:result";
- }
-
- // no more so return null
- return null;
-}
-]]></script>
-</div></div><p>You could also store state as message headers, but they are not
guaranteed to be preserved during routing, where as properties on the <a
shape="rect" href="exchange.html">Exchange</a> are. Although there was a bug in
the method call expression, see the warning below.</p><div
class="confluence-information-macro confluence-information-macro-warning"><p
class="title">Using beans to store state</p><span class="aui-icon
aui-icon-small aui-iconfont-error
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Mind that in Camel 2.9.2 or older,
when using a <a shape="rect" href="bean.html">Bean</a> the state is not
propagated, so you will have to use a <a shape="rect"
href="processor.html">Processor</a> instead. This is fixed in Camel 2.9.3
onwards.</p></div></div><h4 id="DynamicRouter-SpringXML">Spring XML</h4><p>The
same example in Spring XML would be:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent pane
lContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<bean id="mySlip"
class="org.apache.camel.processor.DynamicRouterTest"/>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <dynamicRouter>
- <!-- use a method call on a bean as dynamic router -->
- <method ref="mySlip" method="slip"/>
- </dynamicRouter>
- </route>
-
- <route>
- <from uri="direct:foo"/>
- <transform><constant>Bye
World</constant></transform>
- </route>
-
-</camelContext>
-]]></script>
-</div></div><h4 id="DynamicRouter-@DynamicRouterannotation">@DynamicRouter
annotation</h4><p>You can also use the <code>@DynamicRouter</code> annotation,
for example the Camel 2.4 example below could be written as follows. The
<code>route</code> method would then be invoked repeatedly as the message is
processed dynamically. The idea is to return the next endpoint uri where to go.
Return <code>null</code> to indicate the end. You can return multiple endpoints
if you like, just as the <a shape="rect" href="routing-slip.html">Routing
Slip</a>, where each endpoint is separated by a delimiter.</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[public class MyDynamicRouter {
-
- @Consume(uri = "activemq:foo")
+ @Consume(uri = "activemq:foo")
@DynamicRouter
- public String route(@XPath("/customer/id") String customerId,
@Header("Location") String location, Document body) {
+ public String route(@XPath("/customer/id") String customerId,
@Header("Location") String location, Document body) {
// query a database to find the best match of the endpoint based on
the input parameteres
// return the next endpoint uri, where to go. Return null to indicate
the end.
}
}
-]]></script>
-</div></div><h3 id="DynamicRouter-DynamicRouterinCamel2.4orolder">Dynamic
Router in Camel 2.4 or older</h3><p>The simplest way to implement this is to
use the <a shape="rect" href="recipientlist-annotation.html">RecipientList
Annotation</a> on a Bean method to determine where to route the
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[public class MyDynamicRouter {
+</plain-text-body><h3
id="DynamicRouter-DynamicRouterinCamel2.4orolder">Dynamic Router in Camel 2.4
or older</h3><p>The simplest way to implement this is to use the <a
shape="rect" href="recipientlist-annotation.html">RecipientList Annotation</a>
on a Bean method to determine where to route the message.</p><parameter
ac:name="">java</parameter><plain-text-body>public class MyDynamicRouter {
- @Consume(uri = "activemq:foo")
+ @Consume(uri = "activemq:foo")
@RecipientList
- public List<String> route(@XPath("/customer/id") String
customerId, @Header("Location") String location, Document body) {
+ public List<String> route(@XPath("/customer/id") String customerId,
@Header("Location") String location, Document body) {
// query a database to find the best match of the endpoint based on
the input parameteres
...
}
}
-]]></script>
-</div></div><p>In the above we can use the <a shape="rect"
href="parameter-binding-annotations.html">Parameter Binding Annotations</a> to
bind different parts of the <a shape="rect" href="message.html">Message</a> to
method parameters or use an <a shape="rect"
href="expression.html">Expression</a> such as using <a shape="rect"
href="xpath.html">XPath</a> or <a shape="rect"
href="xquery.html">XQuery</a>.</p><p>The method can be invoked in a number of
ways as described in the <a shape="rect" href="bean-integration.html">Bean
Integration</a> such as</p><ul><li><a shape="rect"
href="pojo-producing.html">POJO Producing</a></li><li><a shape="rect"
href="spring-remoting.html">Spring Remoting</a></li><li><a shape="rect"
href="bean.html">Bean</a> component</li></ul><p></p><h4
id="DynamicRouter-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>
+</plain-text-body><p>In the above we can use the <a shape="rect"
href="parameter-binding-annotations.html">Parameter Binding Annotations</a> to
bind different parts of the <a shape="rect" href="message.html">Message</a> to
method parameters or use an <a shape="rect"
href="expression.html">Expression</a> such as using <a shape="rect"
href="xpath.html">XPath</a> or <a shape="rect"
href="xquery.html">XQuery</a>.</p><p>The method can be invoked in a number of
ways as described in the <a shape="rect" href="bean-integration.html">Bean
Integration</a> such as</p><ul><li><a shape="rect"
href="pojo-producing.html">POJO Producing</a></li><li><a shape="rect"
href="spring-remoting.html">Spring Remoting</a></li><li><a shape="rect"
href="bean.html">Bean</a> component</li></ul><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">