Re: How to make RouteBuilder Spring context aware?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: How to make RouteBuilder Spring context aware?

jstrachan
On 18/01/2008, P.Budzik <[hidden email]> wrote:

>
> I'm pondering on such case:
>
> Suppose:
>
> 1) There is a class that is a plain TestCase subclass
> 2) There is a valid xml camel context definition which is valid Spring
> context definition too.
> 3) This context definition has also some beans defined (say some
> 'components')
> 4) This context file is loaded using Spring's ClasspathXmlApplicationContext
> 5) There are also RouteBuilders defined in that context
>
> Now, how to rip off Spring's ApplicationContext so that it could be
> accessible in RouteBuilder?

Your RouteBuilder could implement ApplicationContexAware, or just have
things from the app context injected.


> We can grab CamelContext from there, but I guess nothing than that. To put
> it simply, how to make RouteBuilder ApplicationContextAware?

public class MyRouteBuilder exends RouteBuilder implements
ApplicationContextAware {
...
}

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

Open Source Integration
http://open.iona.com
Reply | Threaded
Open this post in threaded view
|

Re: How to make RouteBuilder Spring context aware?

P.Budzik
Yeah, of course it works. Thanks. RouteBuilders are plain objects inside the context, so the same rules apply. How could I miss that? :) Anyway probably it's pretty common situation, isn't it? If you are using Camel and wanna make use of Spring (for non-camel components) it seems quite natural to share context with Camel. Although the solution is straightforward IMHO it would be wise to either add such interface+method to RouteBuilder class or even annotation to avoid building base class for route builders as I did.
Reply | Threaded
Open this post in threaded view
|

Re: How to make RouteBuilder Spring context aware?

jstrachan
On 21/01/2008, P.Budzik <[hidden email]> wrote:
>
> Yeah, of course it works. Thanks. RouteBuilders are plain objects inside the
> context, so the same rules apply. How could I miss that? :)

:)

> Anyway probably
> it's pretty common situation, isn't it? If you are using Camel and wanna
> make use of Spring (for non-camel components) it seems quite natural to
> share context with Camel.

Agreed.

Though I guess the proper dependency injection approach is not so much
to inject the ApplicationContext into the RouteBuilder so it can pull
what it needs from there, but to inject the things inside the
ApplicationContext into the RouteBuilder


> Although the solution is straightforward IMHO it
> would be wise to either add such interface+method to RouteBuilder class or
> even annotation to avoid building base class for route builders as I did.

Yeah. We should add more examples that show how to work with
dependency injection and RouteBuilder classes so folks can inject
things into the RouteBuilder


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

Open Source Integration
http://open.iona.com
Reply | Threaded
Open this post in threaded view
|

Re: How to make RouteBuilder Spring context aware?

P.Budzik
James Strachan pisze:
> Though I guess the proper dependency injection approach is not so much
> to inject the ApplicationContext into the RouteBuilder so it can pull
> what it needs from there, but to inject the things inside the
> ApplicationContext into the RouteBuilder

Definitely. That's what I thought initially, however I found no way to
tweak route builders in xml as we have:

<package>....</package>

No clue how to do it :( I guess there is one monolithic beast in the app
context and it is CamelContext with route builders inside.
How to rip them off and instrument?

> Yeah. We should add more examples that show how to work with
> dependency injection and RouteBuilder classes so folks can inject
> things into the RouteBuilder

More is good, but are there any? :)
Reply | Threaded
Open this post in threaded view
|

Re: How to make RouteBuilder Spring context aware?

jstrachan
On 21/01/2008, P.Budzik <[hidden email]> wrote:

> James Strachan pisze:
> > Though I guess the proper dependency injection approach is not so much
> > to inject the ApplicationContext into the RouteBuilder so it can pull
> > what it needs from there, but to inject the things inside the
> > ApplicationContext into the RouteBuilder
>
> Definitely. That's what I thought initially, however I found no way to
> tweak route builders in xml as we have:
>
> <package>....</package>
>
> No clue how to do it :( I guess there is one monolithic beast in the app
> context and it is CamelContext with route builders inside.
> How to rip them off and instrument?

If you configure a RouteBuilder in the XML it will be registered by
default on the CamelContext.

<bean id="myRoute" class="com.acme.MyRouteBuilder>
  <property name="cheese" value="whatever"/>
   ...


> > Yeah. We should add more examples that show how to work with
> > dependency injection and RouteBuilder classes so folks can inject
> > things into the RouteBuilder
>
> More is good, but are there any? :)

LOL

There's some here...
http://activemq.apache.org/camel/examples.html

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

Open Source Integration
http://open.iona.com
Reply | Threaded
Open this post in threaded view
|

Re: How to make RouteBuilder Spring context aware?

P.Budzik
> If you configure a RouteBuilder in the XML it will be registered by
> default on the CamelContext.
>
> <bean id="myRoute" class="com.acme.MyRouteBuilder>
>   <property name="cheese" value="whatever"/>
>    ...

so if it is automagically registered (detecting an instance of route
builder class) that's ok for me.
never tried that.

>>> Yeah. We should add more examples that show how to work with
>>> dependency injection and RouteBuilder classes so folks can inject
>>> things into the RouteBuilder
>> More is good, but are there any? :)
>
> LOL
>
> There's some here...
> http://activemq.apache.org/camel/examples.html

maybe it's funny, but I can't see any example that presents injecting to
route builders. from examples we can learn that we can create route
either by <package> or <route>...</route>. dunno if it is more spring
problem/question than camel question (touches both), but it seems to be
undocumented.


Reply | Threaded
Open this post in threaded view
|

Re: How to make RouteBuilder Spring context aware?

jstrachan
On 21/01/2008, P.Budzik <[hidden email]> wrote:

> > If you configure a RouteBuilder in the XML it will be registered by
> > default on the CamelContext.
> >
> > <bean id="myRoute" class="com.acme.MyRouteBuilder>
> >   <property name="cheese" value="whatever"/>
> >    ...
>
> so if it is automagically registered (detecting an instance of route
> builder class) that's ok for me.
> never tried that.
>
> >>> Yeah. We should add more examples that show how to work with
> >>> dependency injection and RouteBuilder classes so folks can inject
> >>> things into the RouteBuilder
> >> More is good, but are there any? :)
> >
> > LOL
> >
> > There's some here...
> > http://activemq.apache.org/camel/examples.html
>
> maybe it's funny, but I can't see any example that presents injecting to
> route builders. from examples we can learn that we can create route
> either by <package> or <route>...</route>. dunno if it is more spring
> problem/question than camel question (touches both), but it seems to be
> undocumented.

Yeah - we could do with some examples that show that (using spring XML
to configure RouteBuilder instances).


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

Open Source Integration
http://open.iona.com