camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Dead Letter Channel
Date Wed, 15 Jul 2009 08:07:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/Dead+Letter+Channel">Dead
Letter Channel</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="DeadLetterChannel-DeadLetterChannel"></a>Dead Letter
Channel</h2>

<p>Camel supports the <a href="http://www.enterpriseintegrationpatterns.com/DeadLetterChannel.html"
rel="nofollow">Dead Letter Channel</a> from the <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns"
title="Enterprise Integration Patterns">EIP patterns</a> using the <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/processor/DeadLetterChannel.html"
rel="nofollow">DeadLetterChannel</a> processor which is an <a href="/confluence/display/CAMEL/Error+Handler"
title="Error Handler">Error Handler</a>. </p>

<p><img src="http://www.enterpriseintegrationpatterns.com/img/DeadLetterChannelSolution.gif"
align="absmiddle" border="0" /></p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Difference between Dead
Letter Channel and Default Error Handler</b><br /><p>The major difference
is that <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter Channel">Dead
Letter Channel</a> has a dead letter queue that whenever an <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a> could not be processed is moved to. It will <b>always</b>
moved failed exchanges to this queue. </p>

<p>Unlike the <a href="/confluence/display/CAMEL/DefaultErrorHandler" title="DefaultErrorHandler">Default
Error Handler</a> that does <b>not</b> have a dead letter queue. So whenever
an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>
could not be processed the error is propagated back to the client.</p>

<p><b>Notice:</b> You can adjust this behavior of whether the client should
be notified or not with the <b>handled</b> option.</p></td></tr></table></div>

<h3><a name="DeadLetterChannel-Redelivery"></a>Redelivery </h3>

<p>It is common for a temporary outage or database deadlock to cause a message to fail
to process; but the chances are if its tried a few more times with some time delay then it
will complete fine. So we typically wish to use some kind of redelivery policy to decide how
many times to try redeliver a message and how long to wait before redelivery attempts.</p>

<p>The <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/RedeliveryPolicy.html"
rel="nofollow">RedeliveryPolicy</a> defines how the message is to be redelivered.
You can customize things like</p>

<ul>
	<li>how many times a message is attempted to be redelivered before it is considered
a failure and sent to the dead letter channel</li>
	<li>the initial redelivery timeout</li>
	<li>whether or not exponential backoff is used (i.e. the time between retries increases
using a backoff multiplier)</li>
	<li>whether to use collision avoidance to add some randomness to the timings</li>
	<li>delay pattern a new option in Camel 2.0, see below for details.</li>
</ul>


<p>Once all attempts at redelivering the message fails then the message is forwarded
to the dead letter queue.</p>

<h3><a name="DeadLetterChannel-AboutmovingExchangetodeadletterqueueandusinghandled"></a>About
moving Exchange to dead letter queue and using handled</h3>
<p><b>Handled</b> on <a href="/confluence/display/CAMEL/Dead+Letter+Channel"
title="Dead Letter Channel">Dead Letter Channel</a> was introduced in Camel 2.0,
this feature does not exist in Camel 1.x</p>

<p>When all attempts of redelivery have failed the <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a> is moved to the dead letter queue (the dead letter
endpoint). The exchange is then complete and from the client point of view it was processed.
As such the <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter
Channel">Dead Letter Channel</a> have handled the <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a>. </p>

<p>For instance configuring the dead letter channel as:</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">errorHandler(deadLetterChannel("jms:queue:dead").maximumRedeliveries(3).redeliverDealy(5000));</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>The <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter
Channel">Dead Letter Channel</a> above will clear the caused exception when the <a
href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> is moved
to the <tt>jms:queue:dead</tt> destination and the client will not notice the
failure. </p>

<p>By default handled is <tt>true</tt>.</p>

<h4><a name="DeadLetterChannel-Howtolettheclientnoticetheerror%3F"></a>How
to let the client notice the error?</h4>
<p>If you want to move the message to the dead letter queue <b>and</b> also
let the client notice the error, then you can configure the <a href="/confluence/display/CAMEL/Dead+Letter+Channel"
title="Dead Letter Channel">Dead Letter Channel</a> to <b>not</b> handle
the error. For example:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">errorHandler(deadLetterChannel("jms:queue:dead").maximumRedeliveries(3).redeliverDealy(5000).handled(false));</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>When all attempts of redelivery have failed the <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a> is moved to the dead letter queue (the dead letter
endpoint). As the <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter
Channel">Dead Letter Channel</a> <br/>
is configured to <b>not</b> handle it, it will mark the <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a> as failed so the client will be notified of this error.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Handled</b><br
/><p>See also <a href="/confluence/display/CAMEL/Exception+Clause" title="Exception
Clause">Exception Clause</a> for more details on the <b>handled</b> policy
as this feature was first introduced here and thus we have more docuemntation and samples
there.</p></td></tr></table></div>

<h3><a name="DeadLetterChannel-AboutmovingExchangetodeadletterqueueandusingtheoriginalmessage"></a>About
moving Exchange to dead letter queue and using the original message</h3>
<p><b>Available as of Camel 2.0</b><br/>
The option <b>useOriginalMessage</b> is used for routing the original input message
instead of the current message that potentially is modified during routing.</p>

<p>For instance if you have this route:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">from("jms:queue:order:input")
       .to("bean:validateOrder");
       .to("bean:transformOrder")
       .to("bean:handleOrder");</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>

<p>The route listen for JMS messages and validates, transforms and handle it. During
this the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>
payload is transformed/modified. So in case something goes wrong and we want to move the message
to another JMS destination, then we can configure our <a href="/confluence/display/CAMEL/Dead+Letter+Channel"
title="Dead Letter Channel">Dead Letter Channel</a> with the <b>useOriginalBody</b>
option. But when we move the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>
to this destination we do not know in which state the message is in. Did the error happen
in before the transformOrder or after? So to be sure we want to move the original input message
we received from <tt>jms:queue:order:input</tt>. So we can do this by enabling
the <b>useOriginalMessage</b> option as shown below:</p>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">//
will use original body
    errorHandler(deadLetterChannel("jms:queue:dead")
       .useOriginalMessage().mamimumRedeliveries(5).redeliverDelay(5000);</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>Then the messages routed to the <tt>jms:queue:dead</tt> is the original
input. If we want to manually retry we can move the JMS message from the failed to the input
queue, with no problem as the message is the same as the original we received.</p>


<h3><a name="DeadLetterChannel-OnRedelivery"></a>OnRedelivery</h3>
<p><b>Available in Camel 1.6.0 onwards</b></p>

<p>When <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter
Channel">Dead Letter Channel</a> is doing redeliver its possible to configure a <a
href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a> that is
executed just <b>before</b> every redelivery attempt. This can be used for the
situations where you need to alter the message before its redelivered. See below for sample.
</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>onException and onRedeliver</b><br
/><p>In Camel 2.0 we also added support for per <a href="/confluence/display/CAMEL/Exception+Clause"
title="Exception Clause"><b>onException</b></a> to set a <b>onRedeliver</b>.
That means you can do special on redelivery for different exceptions, as opposed to onRedelivery
set on <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter Channel">Dead
Letter Channel</a> can be viewed as a global scope.</p></td></tr></table></div>


<h3><a name="DeadLetterChannel-Redeliverydefaultvalues"></a>Redelivery default
values</h3>
<p>In <b>Camel 2.0</b> redelivery is disabled by default, as opposed to
Camel 1.x in which <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead
Letter Channel">Dead Letter Channel</a> is configured with <tt>maximumRedeliveries=5</tt>.</p>

<p>The default redeliver policy will use the following values:</p>
<ul>
	<li>maximumRedeliveries=0 (in Camel 1.x the default value is 5)</li>
	<li>redeliverDelay=1000L (1 second, <b>new as of Camel 2.0</b>)
	<ul>
		<li>use initialRedeliveryDelay for previous versions</li>
	</ul>
	</li>
	<li>maximumRedeliveryDelay = 60 * 1000L (60 seconds)</li>
	<li>And the exponential backoff and collision avoidance is turned off.</li>
	<li>The retriesExhaustedLogLevel and retryAttemptedLogLevel are set to LoggingLevel.DEBUG</li>
	<li>Stack traces is not logged</li>
</ul>


<p>The maximum redeliver delay ensures that a delay is never longer than the value,
default 1 minute. This can happen if you turn on the exponential backoff.</p>

<p>The maximum redeliveries is the number of <b>re</b> delivery attempts.
By default Camel will try to process the exchange 1 + 5 times. 1 time for the normal attempt
and then 5 attempts as redeliveries.<br/>
Setting the maximumRedeliveries to a negative value such as -1 will then always redelivery
(unlimited).<br/>
Setting the maximumRedeliveries to 0 will disable any re delivery attempt.</p>

<p>Camel will log delivery failures at the DEBUG logging level by default. You can change
this by specifying retriesExhaustedLogLevel and/or retryAttemptedLogLevel. See <a href="http://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithRetryLoggingLevelSetTest.java"
rel="nofollow">ExceptionBuilderWithRetryLoggingLevelSetTest</a> for an example. </p>

<p>In Camel 2.0 you can turn logging of stack traces on/off. If turned off Camel will
still log the redelivery attempt. Its just much less verbose.</p>

<h4><a name="DeadLetterChannel-RedeliverDelayPattern"></a>Redeliver Delay
Pattern</h4>
<p><b>Available as of Camel 2.0</b><br/>
Delay pattern is used as a single option to set a range pattern for delays. If used then the
following options does not apply: (delay, backOffMultiplier, useExponentialBackOff, useCollisionAvoidance,
maximumRedeliveryDelay).</p>

<p>The idea is to set groups of ranges using the following syntax: <tt>limit:delay;limit
2:delay 2;limit 3:delay 3;...;limit N:delay N</tt></p>

<p>Each group has two values separated with colon</p>
<ul class="alternate" type="square">
	<li>limit = upper limit</li>
	<li>delay = delay in millis<br/>
And the groups is again separated with semi colon.<br/>
The rule of thumb is that the next groups should have a higher limit than the previous group.</li>
</ul>


<p>Lets clarify this with an example:<br/>
<tt>delayPattern=5:1000;10:5000;20:20000</tt></p>

<p>That gives us 3 groups:</p>
<ul class="alternate" type="square">
	<li>5:1000</li>
	<li>10:5000</li>
	<li>20:20000</li>
</ul>


<p>Resulting in these delays for redelivery attempt:</p>
<ul class="alternate" type="square">
	<li>Attempt number 0..4 = 0 millis (as the first group start with 5)</li>
	<li>Attempt number 5..9 = 1000 millis (the first group)</li>
	<li>Attempt number 10..19 = 5000 millis (the second group)</li>
	<li>Attempt number 20.. = 20000 millis (the last group)</li>
</ul>


<p>You can start a group with limit 0 to eg have a starting delay: <tt>delayPattern=0:1000;5:5000</tt></p>
<ul class="alternate" type="square">
	<li>Attempt number 0..4 = 1000 millis (the first group)</li>
	<li>Attempt number 5.. = 5000 millis (the last group)</li>
</ul>


<p>There is no requirement that the next delay should be higher than the previous. You
can use any delay value you like. For example with <tt>delayPattern=0:5000;3:1000</tt>
we start with 5 sec delay and then later reduce that to 1 second.</p>

<h3><a name="DeadLetterChannel-Redeliveryheader"></a>Redelivery header</h3>

<p>When a message is redelivered the <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/DeadLetterChannel.html"
rel="nofollow">DeadLetterChannel</a> will append a customizable header to the message
to indicate how many times its been redelivered. <br/>
In Camel 1.x: The header is <b>org.apache.camel.redeliveryCount</b>.<br/>
In Camel 2.0: The header is <b>CamelRedeliveryCount</b>.</p>

<p>And a boolean flag whether it is being redelivered or not (first attempt)<br/>
In Camel 1.x: The header <b>org.apache.camel.Redelivered</b> contains a boolean
if the message is redelivered or not.<br/>
In Camel 2.0: The header <b>CamelRedelivered</b> contains a boolean if the message
is redelivered or not.</p>


<h3><a name="DeadLetterChannel-Samples"></a>Samples</h3>
<p>The following example shows how to configure the Dead Letter Channel configuration
using the <a href="/confluence/display/CAMEL/DSL" title="DSL">DSL</a></p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">RouteBuilder
builder = new RouteBuilder() {
    public void configure() {
        // using dead letter channel with a seda queue for errors
        errorHandler(deadLetterChannel("seda:errors"));

        // here is our route
        from("seda:a").to("seda:b");
    }
};</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>You can also configure the <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/processor/RedeliveryPolicy.html"
rel="nofollow">RedeliveryPolicy</a> as this example shows</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">RouteBuilder
builder = new RouteBuilder() {
    public void configure() {
        // configures dead letter channel to use seda queue for errors and use at most 2 redelveries
        // and exponential backoff
        errorHandler(deadLetterChannel("seda:errors").maximumRedeliveries(2).useExponentialBackOff());

        // here is our route
        from("seda:a").to("seda:b");
    }
};</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h3><a name="DeadLetterChannel-HowcanImodifytheExchangebeforeredelivery%3F"></a>How
can I modify the Exchange before redelivery?</h3>
<p>In <b>Camel 1.6.0</b> we added support directly in <a href="/confluence/display/CAMEL/Dead+Letter+Channel"
title="Dead Letter Channel">Dead Letter Channel</a> to set a <a href="/confluence/display/CAMEL/Processor"
title="Processor">Processor</a> that is executed <b>before</b> each redelivery
attempt. </p>

<p>When <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter
Channel">Dead Letter Channel</a> is doing redeliver its possible to configure a <a
href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a> that is
executed just <b>before</b> every redelivery attempt. This can be used for the
situations where you need to alter the message before its redelivered.  </p>

<p>Here we configure the <a href="/confluence/display/CAMEL/Dead+Letter+Channel"
title="Dead Letter Channel">Dead Letter Channel</a> to use our processor <tt>MyRedeliveryProcessor</tt>
to be executed before each redelivery.</p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">//
we configure our Dead Letter Channel to invoke
// MyRedeliveryProcessor before a redelivery is
// attempted. This allows us to alter the message before
errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(5)
        .onRedelivery(new MyRedeliverPrcessor())
        // setting delay to zero is just to make unit teting faster
        .redeliverDelay(0L));</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<p>And this is the processor <tt>MyRedeliveryProcessor</tt> where we alter
the message. </p>
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">//
This is our processor that is executed before every redelivery attempt
// here we can do what we want in the java code, such as altering the message
public class MyRedeliverPrcessor implements Processor {

    public void process(Exchange exchange) throws Exception {
        // the message is being redelivered so we can alter it

        // we just append the redelivery counter to the body
        // you can of course do all kind of stuff instead
        String body = exchange.getIn().getBody(String.class);
        int count = exchange.getIn().getHeader("CamelRedeliveryCounter", Integer.class);

        exchange.getIn().setBody(body + count);
    }
}</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>


<h4><a name="DeadLetterChannel-UsingThisPattern"></a>Using This Pattern</h4>

<p>If you would like to use this EIP Pattern then please read the <a href="/confluence/display/CAMEL/Getting+Started"
title="Getting Started">Getting Started</a>, you may also find the <a href="/confluence/display/CAMEL/Architecture"
title="Architecture">Architecture</a> useful particularly the description of <a
href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> and <a
href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a>. Then you could try out
some of the <a href="/confluence/display/CAMEL/Examples" title="Examples">Examples</a>
first before trying this pattern out.</p>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Error+Handler" title="Error Handler">Error
Handler</a></li>
	<li><a href="/confluence/display/CAMEL/Exception+Clause" title="Exception Clause">Exception
Clause</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Dead+Letter+Channel">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=49482&revisedVersion=34&originalVersion=33">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Dead+Letter+Channel?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message