I agree that what is available in Camel out of the box is not far from what
I want to achieve, but for this particurlar use case it means a big
difference.
Just compare the first solution (1.) I came up with using direct endpoints
(is this the proxy pattern you are referring to ?) with the route component
one (2.)
1.
<bean id="generateAndSignPdfRouteBuilder"
class="com.xti.poc.camel.route.sample2.GenerateAndSignPdfRouteBuilder"/>
<bean id="signPdfRouteBuilder"
class="com.xti.poc.camel.route.sample2.SignPdfRouteBuilder"/>
<camelContext id="sample-1"
xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="generateAndSignPdfRouteBuilder"/>
<routeBuilder ref="signPdfRouteBuilder"/>
<route>
<from uri="direct:start"/>
<setHeader headerName="signatureReason">
<constant>JustForFun</constant>
</setHeader>
<setHeader headerName="signatureVisible">
<constant>true</constant>
</setHeader>
<setHeader headerName="xslUri">
<constant>com/xti/poc/camel/route/sample1/krusty.xsl</constant>
</setHeader>
<to uri="direct:generateAndSignPdf"/>
<to uri="mock:result"/>
</route>
</camelContext>
2.
<camelContext id="sample-1"
xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<to
uri="route:generateAndSignPdf?signatureReason=JustForFun&signatureVisible=true&xslUri=com/xti/poc/camel/route/sample1/krusty.xsl"/>
<to uri="mock:result"/>
</route>
</camelContext>
The route component solution (2.) doesn't require me to include the
references to the routeBuilders used in the camelcontext (this gets more
complex when you are nesting routes within routes), neither do I have to
copy the headers in a verbose way. Using the url parameters is a much more
elegant solution in this case.
Another reason to use route components is because it allows you to create
parameterizable route abstractions which can be used as a from endpoint.
Take a look at the snippet below where the route is using a route component
to abstract the following actions : receive from direct:start, set the foo
header to the value specified by the parameter and pass the message on to
the next processor in the route.
<route>
<from uri="route:standardActions?foo=Bar"/>
<to
uri="route:generateAndSignPdf?signatureReason=JustForFun&signatureVisible=true&xslUri=com/xti/poc/camel/route/sample1/krusty.xsl"/>
<to uri="mock:result"/>
</route>
I know this is a naive example but at the customer we came up with some
really meaningful abstractions, shielding the solution consultant from
technical details.
I attached a new version of the codebase to this post, it contains both
solutions + tests so you can easily compare.
Best regards,
Kristof
http://camel.465427.n5.nabble.com/file/n3236211/camel-route-solution1and2.zip
camel-route-solution1and2.zip
--
View this message in context:
http://camel.465427.n5.nabble.com/Abstracting-Routes-using-Components-tp3234703p3236211.html
Sent from the Camel - Users mailing list archive at Nabble.com.