camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Talbut <jtal...@tardis.spudsoft>
Subject Correct way to handle transactions acroos multiple routes joined with ActiveMQ
Date Tue, 17 May 2011 08:46:45 GMT

I've got the following three routes:
  <camel:camelContext id="sampleHashCamelContext" >
      <camel:from uri="cxf:bean:serviceEndpoint" />
      <camel:transacted />
      <camel:to uri="activemq:queue:SampleAsyncHashCamelQueue" pattern="InOnly" />

    <camel:route streamCache="true" handleFault="false">
      <camel:from uri="activemq:queue:SampleAsyncHashCamelQueue" />
      <camel:transacted />
        <camel:roundRobin />
        <camel:to uri="cxf:bean:targetEndpoint1"/>
        <camel:to uri="cxf:bean:targetEndpoint2"/>
        <camel:to uri="cxf:bean:targetEndpoint3"/>
      <camel:to uri="activemq:queue:SampleAsyncHashCamelQueueReply" />
      <camel:from uri="activemq:queue:SampleAsyncHashCamelQueueReply" />
      <camel:transacted />
      <camel:to uri="" pattern="InOnly"

In the no-error case everything works perfectly, one of the CXF endpoints gets called asynchronously
and the results get sent to an http endpoint.

To test the error handling I change the CXF endpoints to point to TCP ports that aren't listening.
When I do this for one endpoint everything continues to work correctly.
When I change two endpoints I get the following error:
Interceptor for {}Hash#{}HashFiles has thrown
exception, unwinding now
org.apache.cxf.interceptor.Fault: org.apache.camel.impl.DefaultMessage cannot be cast to org.apache.camel.component.jms.JmsMessage
        at org.apache.camel.component.cxf.CxfConsumer$1.checkFailure([136:org.apache.camel.camel-cxf:2.7.1]
Caused by: java.lang.ClassCastException: org.apache.camel.impl.DefaultMessage cannot be cast
to org.apache.camel.component.jms.JmsMessage
        at org.apache.camel.component.jms.JmsProducer.setMessageId([155:org.apache.camel.camel-jms:2.7.1]

In the docs for transactional-client there is an example of a similar route that has to explicitly
create a new transaction for the second stage.
Should I be doing this?
If so, how does camel know that it should wrap the three routes in a single transaction (i.e.
if something else were to dequeue messages wouldn't that leave the 
transaction hanging?)

If I don't need to explicitly declare transaction policies, what is causing the error?



View raw message