You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Olivier Billard <ol...@gmail.com> on 2010/02/04 17:48:21 UTC

Defining a DeadLetterChannel when using POJO annotations

Hi there,

I am new to Camel, and a little bit disappointed to get the right way to
configure my use case.

- entry point is a JMS queue,
- then a multicast to a second (backup) queue and a content-based router
- the content-based router chooses a WS endpoint based on the XML root
element of the message
- I would like to have a dead letter channel managing inaccessible
webservices, my requirement being not loosing any single message.


jms:startqueue -> multicast (
    -> jms:backupqueue
    -> content-based router (
            {root-element=ws1} -> ws1 endpoint       (I need a dead letter
channel here)
            {root-element=ws2} -> ws2 endpoint       (I need a dead letter
channel here)
  )



I think I did not manage to get to the right documentation (again, new
rider), and the only one corresponding to my content-based router seems to
be the dynamic router, using a POJO and @RecipientList ([1]), as Java DSL
does not seem to handle this case with the classic "Content Based Router".

My question, finally :
I would like to have a dead letter channel managing the inaccessible
webservices, given the fact that I used POJOs annotations to build the
route. I would like not to mix Spring DSL / Java DSL / Beans routing
configuraiton. What I felt was that I could use the errorHandlerRef
attribute of the camelContext Spring element, inspired with the Spring based
configuration sample [2], but it the dead letter channel (a JMS queue in my
case) is not filled.

Using this attribute does not trigger the configured dead letter channel,
with the following configuration :

  <camelContext id="camelContext"
xmlns="http://camel.apache.org/schema/spring"
    errorHandlerRef="myDeadLetterErrorHandler" />


  <!-- here we configure our DeadLetterChannel -->
  <bean id="myDeadLetterErrorHandler"
class="org.apache.camel.builder.DeadLetterChannelBuilder">
    <!-- exchanges is routed to ${router.deadLetter.uri} in case redelivery
failed -->
    <property name="deadLetterUri" value="${router.deadLetter.uri}" />
    <!-- reference the redelivery policy to use -->
    <property name="redeliveryPolicy" ref="myRedeliveryPolicyConfig" />
  </bean>

  <!-- here we set the redelivery settings -->
  <bean id="myRedeliveryPolicyConfig"
class="org.apache.camel.processor.RedeliveryPolicy">
    <!--
      try redelivery at most 3 times, after that the exchange is dead and
its
      routed to the ${router.deadLetter.uri} endpoint
    -->
    <property name="maximumRedeliveries" value="3" />
    <!-- delay 250ms before redelivery -->
    <property name="redeliverDelay" value="250" />
  </bean>


Another solution would be to :
- decouple the content-based router from the WS endpoint, using a "direct:"
channel, and adding a RouteBuilder defining a dead letter channel between
the "direct:" channels and the WS endpoints :

jms:startqueue -> multicast (
    -> jms:backupqueue
    -> content-based router (
            {root-element=ws1} -> direct:ws1 -> ws1 endpoint       (I need a
dead letter channel here)
            {root-element=ws2} -> direct:ws2 -> ws2 endpoint       (I need a
dead letter channel here)
  )


Can someone please help me to find what the problem is, and what would be
the ideal solution ?
Many thanks !

--
Olivier


[1] http://camel.apache.org/dynamic-router.html
[2]
http://camel.apache.org/error-handler.html#ErrorHandler-Springbasedconfigurationsample

-----
--
Olivier Billard
-- 
View this message in context: http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27455914.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Defining a DeadLetterChannel when using POJO annotations

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Feb 5, 2010 at 11:32 AM, Olivier Billard
<ol...@gmail.com> wrote:
>
> Many thanks for your answer, Claus!
>
> I indeed use an ActiveMQ queue as the dead letter channel endpoint.
> But my question was more on the beginning of the Camel pipeline: if a crash
> happens between my two Beans (multicast and content-based router), connected
> via the direct: channels, I suspect them to be lost forever if the pipeline
> is not transaction-enabled, isn't it ? In the case of a transacted pipeline,
> are the messages kept on the original JMS queue entry point if the crash
> happens?
>
> Or must I implement a "guaranteed delivery channel", by using JMS queues
> instead of direct channels ? In this case, this would do a lot of traffic
> between Camel and the broker, even if the 2 of them are quite near in my
> architecture...
>

No if you enable transaction on the JMS consumer and tell Camel its a
transacted route then that will last for the duration of the routing.

See more here
http://camel.apache.org/transactional-client.html

And even better chapter 9 in the Camel in Action book which is devoted
to transactions.



>
> Sorry if I missed a point on Camel, I really am new to it :)
> --
> Olivier
>
>
>
> Claus Ibsen-2 wrote:
>>
>> On Fri, Feb 5, 2010 at 10:08 AM, Olivier Billard
>> <ol...@gmail.com> wrote:
>>>
>>> Hi Claus,
>>>
>>> Unfortunately, this issue reproduces with the last 2.2-SNAPSHOTS
>>> artifacts
>>> from the apache.snapshots repo...
>>> I managed to workaround it the way I previously explained :
>>> - routing the multicast bean to a "direct:webservices" channel,
>>> - wiring "direct:webservices" and
>>> "direct:webservices-with-deadletterchannel" channels with a RouteBuilder
>>> defining a dead letter channel
>>> - my content-based router consumes the
>>> "direct:webservices-with-deadletterchannel", and drives the messages
>>> along
>>> the webservices
>>>
>>> That's not clean, I am not satisfied with this, but this works for the
>>> moment. But the risk here of loosing messages is higher, isn't it ? Could
>>> the use of a transactional error handling bring something here with the
>>> direct channels ?
>>>
>>
>> You can use transactional JMS and use the JMS broker dead letter channel.
>> If using AMQ then check their documentation how to.
>>
>>
>>
>>> --
>>> Olivier
>>>
>>>
>>> Claus Ibsen-2 wrote:
>>>>
>>>> On Thu, Feb 4, 2010 at 11:02 PM, Olivier Billard
>>>> <ol...@gmail.com> wrote:
>>>>>
>>>>> Yep, sorry, I am using the latest stable release : 2.1.0.
>>>>>
>>>>
>>>> Can you try 2.2-SNAPSHOT or wait till 2.2 is released.
>>>> http://camel.apache.org/download.html
>>>>
>>>> I think we fixed an issue with setting error handler ref on camel
>>>> context.
>>>>
>>>> --
>>>> Claus Ibsen
>>>> Apache Camel Committer
>>>>
>>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>> Open Source Integration: http://fusesource.com
>>>> Blog: http://davsclaus.blogspot.com/
>>>> Twitter: http://twitter.com/davsclaus
>>>>
>>>>
>>>
>>>
>>> -----
>>> --
>>> Olivier Billard
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27465224.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
>
> -----
> --
> Olivier Billard
> --
> View this message in context: http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27466003.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Defining a DeadLetterChannel when using POJO annotations

Posted by Olivier Billard <ol...@gmail.com>.
Many thanks for your answer, Claus!

I indeed use an ActiveMQ queue as the dead letter channel endpoint.
But my question was more on the beginning of the Camel pipeline: if a crash
happens between my two Beans (multicast and content-based router), connected
via the direct: channels, I suspect them to be lost forever if the pipeline
is not transaction-enabled, isn't it ? In the case of a transacted pipeline,
are the messages kept on the original JMS queue entry point if the crash
happens?

Or must I implement a "guaranteed delivery channel", by using JMS queues
instead of direct channels ? In this case, this would do a lot of traffic
between Camel and the broker, even if the 2 of them are quite near in my
architecture...


Sorry if I missed a point on Camel, I really am new to it :)
--
Olivier



Claus Ibsen-2 wrote:
> 
> On Fri, Feb 5, 2010 at 10:08 AM, Olivier Billard
> <ol...@gmail.com> wrote:
>>
>> Hi Claus,
>>
>> Unfortunately, this issue reproduces with the last 2.2-SNAPSHOTS
>> artifacts
>> from the apache.snapshots repo...
>> I managed to workaround it the way I previously explained :
>> - routing the multicast bean to a "direct:webservices" channel,
>> - wiring "direct:webservices" and
>> "direct:webservices-with-deadletterchannel" channels with a RouteBuilder
>> defining a dead letter channel
>> - my content-based router consumes the
>> "direct:webservices-with-deadletterchannel", and drives the messages
>> along
>> the webservices
>>
>> That's not clean, I am not satisfied with this, but this works for the
>> moment. But the risk here of loosing messages is higher, isn't it ? Could
>> the use of a transactional error handling bring something here with the
>> direct channels ?
>>
> 
> You can use transactional JMS and use the JMS broker dead letter channel.
> If using AMQ then check their documentation how to.
> 
> 
> 
>> --
>> Olivier
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> On Thu, Feb 4, 2010 at 11:02 PM, Olivier Billard
>>> <ol...@gmail.com> wrote:
>>>>
>>>> Yep, sorry, I am using the latest stable release : 2.1.0.
>>>>
>>>
>>> Can you try 2.2-SNAPSHOT or wait till 2.2 is released.
>>> http://camel.apache.org/download.html
>>>
>>> I think we fixed an issue with setting error handler ref on camel
>>> context.
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>>
>>
>>
>> -----
>> --
>> Olivier Billard
>> --
>> View this message in context:
>> http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27465224.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 


-----
--
Olivier Billard
-- 
View this message in context: http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27466003.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Defining a DeadLetterChannel when using POJO annotations

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Feb 5, 2010 at 10:08 AM, Olivier Billard
<ol...@gmail.com> wrote:
>
> Hi Claus,
>
> Unfortunately, this issue reproduces with the last 2.2-SNAPSHOTS artifacts
> from the apache.snapshots repo...
> I managed to workaround it the way I previously explained :
> - routing the multicast bean to a "direct:webservices" channel,
> - wiring "direct:webservices" and
> "direct:webservices-with-deadletterchannel" channels with a RouteBuilder
> defining a dead letter channel
> - my content-based router consumes the
> "direct:webservices-with-deadletterchannel", and drives the messages along
> the webservices
>
> That's not clean, I am not satisfied with this, but this works for the
> moment. But the risk here of loosing messages is higher, isn't it ? Could
> the use of a transactional error handling bring something here with the
> direct channels ?
>

You can use transactional JMS and use the JMS broker dead letter channel.
If using AMQ then check their documentation how to.



> --
> Olivier
>
>
> Claus Ibsen-2 wrote:
>>
>> On Thu, Feb 4, 2010 at 11:02 PM, Olivier Billard
>> <ol...@gmail.com> wrote:
>>>
>>> Yep, sorry, I am using the latest stable release : 2.1.0.
>>>
>>
>> Can you try 2.2-SNAPSHOT or wait till 2.2 is released.
>> http://camel.apache.org/download.html
>>
>> I think we fixed an issue with setting error handler ref on camel context.
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
>
> -----
> --
> Olivier Billard
> --
> View this message in context: http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27465224.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Defining a DeadLetterChannel when using POJO annotations

Posted by Olivier Billard <ol...@gmail.com>.
Hi Claus,

Unfortunately, this issue reproduces with the last 2.2-SNAPSHOTS artifacts
from the apache.snapshots repo...
I managed to workaround it the way I previously explained :
- routing the multicast bean to a "direct:webservices" channel,
- wiring "direct:webservices" and
"direct:webservices-with-deadletterchannel" channels with a RouteBuilder
defining a dead letter channel
- my content-based router consumes the
"direct:webservices-with-deadletterchannel", and drives the messages along
the webservices

That's not clean, I am not satisfied with this, but this works for the
moment. But the risk here of loosing messages is higher, isn't it ? Could
the use of a transactional error handling bring something here with the
direct channels ? 

--
Olivier


Claus Ibsen-2 wrote:
> 
> On Thu, Feb 4, 2010 at 11:02 PM, Olivier Billard
> <ol...@gmail.com> wrote:
>>
>> Yep, sorry, I am using the latest stable release : 2.1.0.
>>
> 
> Can you try 2.2-SNAPSHOT or wait till 2.2 is released.
> http://camel.apache.org/download.html
> 
> I think we fixed an issue with setting error handler ref on camel context.
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 


-----
--
Olivier Billard
-- 
View this message in context: http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27465224.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Defining a DeadLetterChannel when using POJO annotations

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Feb 4, 2010 at 11:02 PM, Olivier Billard
<ol...@gmail.com> wrote:
>
> Yep, sorry, I am using the latest stable release : 2.1.0.
>

Can you try 2.2-SNAPSHOT or wait till 2.2 is released.
http://camel.apache.org/download.html

I think we fixed an issue with setting error handler ref on camel context.


>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> Please remember to tell the versions of the product you use. Its a
>> vital information.
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
>
> -----
> --
> Olivier Billard
> --
> View this message in context: http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27460454.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Defining a DeadLetterChannel when using POJO annotations

Posted by Olivier Billard <ol...@gmail.com>.
Yep, sorry, I am using the latest stable release : 2.1.0.



Claus Ibsen-2 wrote:
> 
> Hi
> 
> Please remember to tell the versions of the product you use. Its a
> vital information.
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 


-----
--
Olivier Billard
-- 
View this message in context: http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27460454.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Defining a DeadLetterChannel when using POJO annotations

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Please remember to tell the versions of the product you use. Its a
vital information.


On Thu, Feb 4, 2010 at 5:48 PM, Olivier Billard
<ol...@gmail.com> wrote:
>
> Hi there,
>
> I am new to Camel, and a little bit disappointed to get the right way to
> configure my use case.
>
> - entry point is a JMS queue,
> - then a multicast to a second (backup) queue and a content-based router
> - the content-based router chooses a WS endpoint based on the XML root
> element of the message
> - I would like to have a dead letter channel managing inaccessible
> webservices, my requirement being not loosing any single message.
>
>
> jms:startqueue -> multicast (
>    -> jms:backupqueue
>    -> content-based router (
>            {root-element=ws1} -> ws1 endpoint       (I need a dead letter
> channel here)
>            {root-element=ws2} -> ws2 endpoint       (I need a dead letter
> channel here)
>  )
>
>
>
> I think I did not manage to get to the right documentation (again, new
> rider), and the only one corresponding to my content-based router seems to
> be the dynamic router, using a POJO and @RecipientList ([1]), as Java DSL
> does not seem to handle this case with the classic "Content Based Router".
>
> My question, finally :
> I would like to have a dead letter channel managing the inaccessible
> webservices, given the fact that I used POJOs annotations to build the
> route. I would like not to mix Spring DSL / Java DSL / Beans routing
> configuraiton. What I felt was that I could use the errorHandlerRef
> attribute of the camelContext Spring element, inspired with the Spring based
> configuration sample [2], but it the dead letter channel (a JMS queue in my
> case) is not filled.
>
> Using this attribute does not trigger the configured dead letter channel,
> with the following configuration :
>
>  <camelContext id="camelContext"
> xmlns="http://camel.apache.org/schema/spring"
>    errorHandlerRef="myDeadLetterErrorHandler" />
>
>
>  <!-- here we configure our DeadLetterChannel -->
>  <bean id="myDeadLetterErrorHandler"
> class="org.apache.camel.builder.DeadLetterChannelBuilder">
>    <!-- exchanges is routed to ${router.deadLetter.uri} in case redelivery
> failed -->
>    <property name="deadLetterUri" value="${router.deadLetter.uri}" />
>    <!-- reference the redelivery policy to use -->
>    <property name="redeliveryPolicy" ref="myRedeliveryPolicyConfig" />
>  </bean>
>
>  <!-- here we set the redelivery settings -->
>  <bean id="myRedeliveryPolicyConfig"
> class="org.apache.camel.processor.RedeliveryPolicy">
>    <!--
>      try redelivery at most 3 times, after that the exchange is dead and
> its
>      routed to the ${router.deadLetter.uri} endpoint
>    -->
>    <property name="maximumRedeliveries" value="3" />
>    <!-- delay 250ms before redelivery -->
>    <property name="redeliverDelay" value="250" />
>  </bean>
>
>
> Another solution would be to :
> - decouple the content-based router from the WS endpoint, using a "direct:"
> channel, and adding a RouteBuilder defining a dead letter channel between
> the "direct:" channels and the WS endpoints :
>
> jms:startqueue -> multicast (
>    -> jms:backupqueue
>    -> content-based router (
>            {root-element=ws1} -> direct:ws1 -> ws1 endpoint       (I need a
> dead letter channel here)
>            {root-element=ws2} -> direct:ws2 -> ws2 endpoint       (I need a
> dead letter channel here)
>  )
>
>
> Can someone please help me to find what the problem is, and what would be
> the ideal solution ?
> Many thanks !
>
> --
> Olivier
>
>
> [1] http://camel.apache.org/dynamic-router.html
> [2]
> http://camel.apache.org/error-handler.html#ErrorHandler-Springbasedconfigurationsample
>
> -----
> --
> Olivier Billard
> --
> View this message in context: http://old.nabble.com/Defining-a-DeadLetterChannel-when-using-POJO-annotations-tp27455914p27455914.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus