You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ddewaele <dd...@gmail.com> on 2013/03/05 14:43:09 UTC

Camel multiple (nested) routes in one context

Hi,

I have a Camel Spring XML where I define a camelcontext containing 2 routes.
The main route is embedded inside the camlContext.
At some point in the main route, based on someCondition, I need to decide to
do either 

 * standard processing (here I just need trigger a single camel processor)
 * complex processing (here I would like to jump into a new route).

The reason why the complex-route was introduced was simply to encapsulate
the steps required to do the complex processing. 

Question : Is this the correct way of doing it (defining a new route and
jumping into that route from an existing route) ?



This seems to work fine except for one thing :

Both the main-route and the complex-route have an onException element.
When an exception occurs and even when complexProcessingRequired=false and
the complex-route is never triggered, sometimes the onException block of the
complex-route is triggered instead of the onException block of the
main-route.

Question : any ideas why it would trigger an onException block of the
complex-route during standard processing (complexProcessingRequired=false)

Thanks in advance




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-multiple-nested-routes-in-one-context-tp5728576.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel multiple (nested) routes in one context

Posted by ddewaele <dd...@gmail.com>.
Hi,

We're a couple of days away from going into production so we're not going to
change the camel version.

But I will upgrade to the latest version of Camel and re-test it soon....
For the moment we just moved the onExeption component outside of the flow.






--
View this message in context: http://camel.465427.n5.nabble.com/Camel-multiple-nested-routes-in-one-context-tp5728576p5729096.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel multiple (nested) routes in one context

Posted by Christian Müller <ch...@gmail.com>.
Can you try Camel 2.10.4?

http://camel.apache.org/download.html

Best,
Christian

On Wed, Mar 6, 2013 at 10:15 AM, ddewaele <dd...@gmail.com> wrote:

> Hi,
>
> We're using 2.10.1.
>
> Any idea about the logging (don't know if this is related) ? The fact that
> it added "complex-route" instead of "main-route" in the log for an exchange
> that never entered the complex-route ?
>
> [Camel (camelContext) thread #8 - vm://input] complex-route - Using real
> dispatcher
>
> A design-related question :
>
> The reason why the complex-route was introduced was to encapsulate a number
> of steps that needed to be done on an exchange.
> Is this a good candidate for creating a new route , and effectively nesting
> it in another route by having the main-route send the exchange to the
> from-endpoint of the complex-route ? (as is being done here).
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-multiple-nested-routes-in-one-context-tp5728576p5728652.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--

Re: Camel multiple (nested) routes in one context

Posted by ddewaele <dd...@gmail.com>.
Hi,

We're using 2.10.1.

Any idea about the logging (don't know if this is related) ? The fact that
it added "complex-route" instead of "main-route" in the log for an exchange
that never entered the complex-route ?

[Camel (camelContext) thread #8 - vm://input] complex-route - Using real
dispatcher 

A design-related question : 

The reason why the complex-route was introduced was to encapsulate a number
of steps that needed to be done on an exchange. 
Is this a good candidate for creating a new route , and effectively nesting
it in another route by having the main-route send the exchange to the
from-endpoint of the complex-route ? (as is being done here).



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-multiple-nested-routes-in-one-context-tp5728576p5728652.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel multiple (nested) routes in one context

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

What Camel version do you use.

We had a bug a while back with the onException may select the wrong one.


On Wed, Mar 6, 2013 at 9:14 AM, ddewaele <dd...@gmail.com> wrote:
> I guess the xml snippet  got lost in the markup....
>
> I've simplified the flows somewhat but everything should be in there....
>
> The main questions are :
>
>  * why is the complex-route's onException triggered when an exchange never
> went into the complex-route but stayed in the main-route
>  * logging :  why it uses complex-route and not main-route in the logging
> for the "Using real dispatcher" log statement. (again for exchanges that
> never went into the complex-route.
>
> I've put the 2 snippets in the following Gist as well :
> https://gist.github.com/ddewaele/5097516
>
> The "design" was based on the  How do I import routes from other XML files
> <http://camel.apache.org/how-do-i-import-routes-from-other-xml-files.html>
> article, but there we have 2 independent routes, where here we have nested
> routes.
>
> main-flow :
>
> <beans xmlns="http://www.springframework.org/schema/beans">
>
>   <import resource="camel-complex-route.xml"/>
>
>         <camel:camelContext xmlns="http://camel.apache.org/schema/spring"
> id="camelContext" useMDCLogging="true">
>
>                 <camel:routeContextRef ref="complex-route-context"/>
>
>                 <--
>                 Here we also noticed that in the logging the "Using real dispatcher" log
> statement was logged like this :
>                 2013-03-06 09:00:29.665 [Camel (camelContext) thread #8 - vm://input]
> complex-route - Using real dispatcher
>
>                 Notice how it uses complex-route and not main-route
>                 -->
>
>
>                 <camel:interceptSendToEndpoint
> uri="http4://endpoint?throwExceptionOnFailure=false"
> skipSendToOriginalEndpoint="true">
>                         <choice>
>                         <when>
>                                 <simple>${header.header1}</simple>
>                                 <log message="Faking dispatcher"/>
>                         <bean ref="fakeDispatcher" method="dispatch" />
>                         </when>
>                         <when>
>                                 <simple>${header.header2}</simple>
>                                 <log message="Overriding dispatcher"/>
>                                 <setHeader headerName="CamelHttpUri">
>
> <simple>http://localhost:8085/overridden-service/${service_name}</simple>
>                         </setHeader>
>                         <to uri="http4://endpoint?throwExceptionOnFailure=false" />
>                         </when>
>                     <otherwise>
>                                 <log message="Using real dispatcher"/>
>                         <to uri="http4://endpoint?throwExceptionOnFailure=false" />
>                     </otherwise>
>                     </choice>
>         </camel:interceptSendToEndpoint>
>
>                 <camel:route id="main-route" streamCache="true">
>
>                         <camel:from id="camelservlet"
> uri="servlet:///someUrl?httpBindingRef=mfBinding&amp;matchOnUriPrefix=true"
> />
>
>                         <--  entry point for the main flow -->
>                         <camel:from uri="vm:input" />
>
>                         <camel:onException>
>                                 <camel:exception>java.lang.Exception</camel:exception>
>                                 <camel:handled>
>                                         <constant>true</constant>
>                                 </camel:handled>
>                                 <camel:process ref="exceptionProcessor" />
>                                 <camel:process ref="process4" />
>                                 <camel:process ref="process5" />
>                         </camel:onException>
>                         <camel:process ref="process1" />
>                         <camel:process ref="process2" />
>                         <camel:process ref="process3" />
>
>                         <--
>                         Dispatch Message.
>                         Here we decide
>                                 to use complex processing ( = entering the complex route)
>                                 to use simple processing ( = simple dispatching and never entering the
> complex route)
>
>                         We noticed that when an exception occured during simple processing (and
> the complex route was never entered),
>                         the onException from the complex route was triggered, instead of the
> onException from the mainFlow.
>                         -->
>                         <choice>
>                                 <when>
>                                         <simple>${header.complexProcessingRequired}"</simple>
>                                         <log message="Using complex processing"/>
>                                         <to uri="direct:complex-route-in"/>
>                                 </when>
>                             <otherwise>
>                                 <log message="Using simple processing"/>
>                                 <to uri="http4://endpoint?throwExceptionOnFailure=false" />
>                             </otherwise>
>                         </choice>
>
>                         <camel:process ref="process4" />
>                         <camel:process ref="process5" />
>                 </camel:route>
>
>         </camel:camelContext>
>
>
> </beans>
>
>
> complex-flow
>
> <beans >
>
>   <camel:routeContext id="complex-route-context">
>
>
>                 <camel:route id="complex-route" streamCache="true">
>
>                         <-- our main flow uses this from endpoint to enter this route -->
>                         <camel:from uri="direct:complex-route-in" />
>
>                         <-- when an exchange in our main route never entered this route, this
> onException is still getting called. -->
>                         <camel:onException>
>                                 <camel:exception>java.lang.Exception</camel:exception>
>                                 <camel:handled>
>                                         <camel:constant>true</camel:constant>
>                                 </camel:handled>
>                                 <camel:process ref="exceptionProcessor" />
>                                 <camel:process ref="complexprocess4" />
>                                 <camel:process ref="complexprocess5" />
>                         </camel:onException>
>
>                         <camel:process ref="complexprocess1" />
>                         <camel:process ref="complexprocess2" />
>                         <camel:process ref="complexprocess3" />
>
>
>                 </camel:route>
>
>         </camel:routeContext>
> </beans>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-multiple-nested-routes-in-one-context-tp5728576p5728643.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Camel multiple (nested) routes in one context

Posted by ddewaele <dd...@gmail.com>.
I guess the xml snippet  got lost in the markup....

I've simplified the flows somewhat but everything should be in there....

The main questions are :

 * why is the complex-route's onException triggered when an exchange never
went into the complex-route but stayed in the main-route
 * logging :  why it uses complex-route and not main-route in the logging
for the "Using real dispatcher" log statement. (again for exchanges that
never went into the complex-route.

I've put the 2 snippets in the following Gist as well :
https://gist.github.com/ddewaele/5097516

The "design" was based on the  How do I import routes from other XML files
<http://camel.apache.org/how-do-i-import-routes-from-other-xml-files.html>  
article, but there we have 2 independent routes, where here we have nested
routes.

main-flow :

<beans xmlns="http://www.springframework.org/schema/beans">
 
  <import resource="camel-complex-route.xml"/>
	
	<camel:camelContext xmlns="http://camel.apache.org/schema/spring"
id="camelContext" useMDCLogging="true">
 
		<camel:routeContextRef ref="complex-route-context"/>
 
		<--
		Here we also noticed that in the logging the "Using real dispatcher" log
statement was logged like this :
		2013-03-06 09:00:29.665 [Camel (camelContext) thread #8 - vm://input] 
complex-route - Using real dispatcher
		
		Notice how it uses complex-route and not main-route
		-->
 
			
		<camel:interceptSendToEndpoint
uri="http4://endpoint?throwExceptionOnFailure=false"
skipSendToOriginalEndpoint="true">
			<choice>
			<when>
				<simple>${header.header1}</simple>
				<log message="Faking dispatcher"/>
		    	<bean ref="fakeDispatcher" method="dispatch" />
			</when>
			<when>
				<simple>${header.header2}</simple>
				<log message="Overriding dispatcher"/>
				<setHeader headerName="CamelHttpUri">
				
<simple>http://localhost:8085/overridden-service/${service_name}</simple>
		    	</setHeader>
		    	<to uri="http4://endpoint?throwExceptionOnFailure=false" />	
			</when>
		    <otherwise>
				<log message="Using real dispatcher"/>
		    	<to uri="http4://endpoint?throwExceptionOnFailure=false" />
		    </otherwise>
		    </choice>
    	</camel:interceptSendToEndpoint>
 		
		<camel:route id="main-route" streamCache="true">
 
			<camel:from id="camelservlet"
uri="servlet:///someUrl?httpBindingRef=mfBinding&amp;matchOnUriPrefix=true"
/>
			
			<--  entry point for the main flow -->			
			<camel:from uri="vm:input" />
			
			<camel:onException>
				<camel:exception>java.lang.Exception</camel:exception>
				<camel:handled>
					<constant>true</constant>
				</camel:handled>
				<camel:process ref="exceptionProcessor" />
				<camel:process ref="process4" />
				<camel:process ref="process5" />
			</camel:onException>
			<camel:process ref="process1" />
			<camel:process ref="process2" />
			<camel:process ref="process3" />
 
			<--  
			Dispatch Message.
			Here we decide 
				to use complex processing ( = entering the complex route)
				to use simple processing ( = simple dispatching and never entering the
complex route)
			
			We noticed that when an exception occured during simple processing (and
the complex route was never entered), 
			the onException from the complex route was triggered, instead of the
onException from the mainFlow.
			-->
			<choice>
				<when>
					<simple>${header.complexProcessingRequired}"</simple>
					<log message="Using complex processing"/>
					<to uri="direct:complex-route-in"/>    	
				</when>
			    <otherwise>
			    	<log message="Using simple processing"/>
			    	<to uri="http4://endpoint?throwExceptionOnFailure=false" />
			    </otherwise>				
			</choice>
			
			<camel:process ref="process4" />
			<camel:process ref="process5" />
		</camel:route>
 
	</camel:camelContext>
 
 
</beans>


complex-flow

<beans >
 
  <camel:routeContext id="complex-route-context">
        
        
		<camel:route id="complex-route" streamCache="true">
			
			<-- our main flow uses this from endpoint to enter this route -->
			<camel:from uri="direct:complex-route-in" />
 
			<-- when an exchange in our main route never entered this route, this
onException is still getting called. -->
			<camel:onException>
				<camel:exception>java.lang.Exception</camel:exception>
				<camel:handled>
					<camel:constant>true</camel:constant>
				</camel:handled>
				<camel:process ref="exceptionProcessor" />
				<camel:process ref="complexprocess4" />
				<camel:process ref="complexprocess5" />
			</camel:onException>
						
			<camel:process ref="complexprocess1" />
			<camel:process ref="complexprocess2" />
			<camel:process ref="complexprocess3" />
		
			 			
		</camel:route>
	
	</camel:routeContext>
</beans>



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-multiple-nested-routes-in-one-context-tp5728576p5728643.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel multiple (nested) routes in one context

Posted by Raúl Kripalani <ra...@evosent.com>.
Could you post some code to illustrate your case, so we can provide more accurate feedback? The way that onException handlers are set up depends on whether you use Java DSL or Spring DSL.

Regards,
Raúl.

On Mar 5, 2013, at 13:43, ddewaele wrote:

> Hi,
> 
> I have a Camel Spring XML where I define a camelcontext containing 2 routes.
> The main route is embedded inside the camlContext.
> At some point in the main route, based on someCondition, I need to decide to
> do either 
> 
> * standard processing (here I just need trigger a single camel processor)
> * complex processing (here I would like to jump into a new route).
> 
> The reason why the complex-route was introduced was simply to encapsulate
> the steps required to do the complex processing. 
> 
> Question : Is this the correct way of doing it (defining a new route and
> jumping into that route from an existing route) ?
> 
> 
> 
> This seems to work fine except for one thing :
> 
> Both the main-route and the complex-route have an onException element.
> When an exception occurs and even when complexProcessingRequired=false and
> the complex-route is never triggered, sometimes the onException block of the
> complex-route is triggered instead of the onException block of the
> main-route.
> 
> Question : any ideas why it would trigger an onException block of the
> complex-route during standard processing (complexProcessingRequired=false)
> 
> Thanks in advance
> 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-multiple-nested-routes-in-one-context-tp5728576.html
> Sent from the Camel - Users mailing list archive at Nabble.com.