You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by "Olivier.Roger" <ol...@bsb.com> on 2010/10/07 12:25:17 UTC

[Spring] Multiple Camel Route in separate bundles

Hello,

I am using SMX to deploy Camel routes. I encountered an unexpected behavior
when deploying multiple routes in the same runtime.

When deployed alone, route behave as expected.
But when I add new routes, the Spring context appears to have issues.

The route starts correctly but, when a message cross a bean on its path I
get this error:
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in
the registry for: [...]

The strange part is that the bean is declared in the same Spring context
that holds the CamelContext.
I thought that deploying multiple route would create multiple classloader,
each having his own beans.

Any idea of what might happen ?
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Spring-Multiple-Camel-Route-in-separate-bundles-tp3202796p3202796.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [Spring] Multiple Camel Route in separate bundles

Posted by JacobS <ja...@gmail.com>.
Hi,

I also have the same problem. Have you managed to solve it ?
http://camel.465427.n5.nabble.com/split-with-spring-DSL-bean-td3405576.html

Thanks 
Jacob

--
View this message in context: http://servicemix.396122.n5.nabble.com/Spring-Multiple-Camel-Route-in-separate-bundles-tp3202796p3408132.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [Spring] Multiple Camel Route in separate bundles

Posted by "Olivier.Roger" <ol...@bsb.com>.
I did not know about that, thanks James.
I will switch to the NMR protocol instead then.

However, this will not solve my issue as the message was sent through vm:B
to the 2nd route.

What seems strange to me is that the route started correctly, which means it
found the bean used in the route. Otherwise I would have had a
FailedToCreateRouteException.

So how, if the route is in started state, could the bean not be found in the
registry ?
-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Spring-Multiple-Camel-Route-in-separate-bundles-tp3202796p3202926.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [Spring] Multiple Camel Route in separate bundles

Posted by James Strachan <ja...@gmail.com>.
On 7 October 2010 13:10, Olivier.Roger <ol...@bsb.com> wrote:
>
> If I understand correctly, this method can only be applied when using bean
> from another bundle.
>
> In my case the problem is a bit different as each route is self-sufficient.
> But when I deploy them together, bean declared in the same spring context as
> the route cannot be found.
>
> At the moment my route are using vm: protocol to exchange messages.
>
> A simple version can be summarize to
>
> Route 1 : jms:A -> vm:B
> Route 2 : vm:B -> bean:C
>
> Each route has its own Spring context (which contains a CamelContext). Bean
> C is declared in Route 2 Spring context.
>
> Did I miss something ?

The vm transport in Camel only works with other vm endpoints within
the exact same class loader. Are you reusing the same underlying Camel
bundles across your route bundles?

Depending on your class loader setup, different bundles may not be
able to communicate over vm transport. Try replacing the "vm"
endpoints with the "nmr" endpoints which are designed to work across
any version of Camel (or use "jms" endpoints to span both class loader
and JVM boundaries).

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Re: [Spring] Multiple Camel Route in separate bundles

Posted by "Olivier.Roger" <ol...@bsb.com>.
If I understand correctly, this method can only be applied when using bean
from another bundle.

In my case the problem is a bit different as each route is self-sufficient.
But when I deploy them together, bean declared in the same spring context as
the route cannot be found.

At the moment my route are using vm: protocol to exchange messages.

A simple version can be summarize to 

Route 1 : jms:A -> vm:B
Route 2 : vm:B -> bean:C

Each route has its own Spring context (which contains a CamelContext). Bean
C is declared in Route 2 Spring context.

Did I miss something ?


-- 
View this message in context: http://servicemix.396122.n5.nabble.com/Spring-Multiple-Camel-Route-in-separate-bundles-tp3202796p3202905.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: [Spring] Multiple Camel Route in separate bundles

Posted by Adrian Trenaman <tr...@progress.com>.
  Hi Olivier,

Would need to see the code I think. However, I can say that if (as per 
the subject line) the routes are defined in different bundles, then each 
bundle has it's own camel context, and so beans visible to a route in 
one camel/spring context might not be visible in another.

In general, if you want to invoke on a bean defined in another bundle, 
you should declare the bean as an OSGi service in the other bundle 
(using <osgi:service ....>) , and then create an OSGi reference to that 
bean in the bundle with your route (<osgi:reference ...>). Then, your 
Camel route can use the bean component to invoke on the local reference, 
which will hook up to the object in the other bundle.

Magic!

/Ade

On 07/10/2010 11:25, Olivier.Roger wrote:
> Hello,
>
> I am using SMX to deploy Camel routes. I encountered an unexpected behavior
> when deploying multiple routes in the same runtime.
>
> When deployed alone, route behave as expected.
> But when I add new routes, the Spring context appears to have issues.
>
> The route starts correctly but, when a message cross a bean on its path I
> get this error:
> Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in
> the registry for: [...]
>
> The strange part is that the bean is declared in the same Spring context
> that holds the CamelContext.
> I thought that deploying multiple route would create multiple classloader,
> each having his own beans.
>
> Any idea of what might happen ?