You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by souciance <so...@gmail.com> on 2016/08/07 13:50:31 UTC

Dynamic bean name injection

Hello,

I am in the middle of refactoring several routes into a template route. We
have some beans in our blueprint xml (use to configure the camelcontext -
rest is java dsl) like this:

<bean id="a1" class="com.home.MyA1Bean"/>
<bean id="a2" class="com.home.MyA2Bean"/>
<bean id="a3" class="com.home.MyA3Bean"/>
<bean id="a4" class="com.home.MyA4Bean"/>
<bean id="a5" class="com.home.MyA5Bean"/>

The route references look similar to:
  <bean id="route1" class="com.home.route">
        <property........./>
    </bean> 
  <bean id="route2" class="com.home.route">
        <property........./>
    </bean> 
  <bean id="route3" class="com.home.route">
        <property........./>
    </bean> 
  <bean id="route4" class="com.home.route">
        <property........./>
    </bean> 
  <bean id="route5" class="com.home.route">
        <property........./>
    </bean> 

Then in the camelcontext:
<camelContext id="context" xmlns="http://camel.apache.org/schema/blueprint">
        <routeBuilder ref="route1"/>
        <routeBuilder ref="route2"/>
        <routeBuilder ref="route3"/>
        <routeBuilder ref="route4"/>
        <routeBuilder ref="route5"/>
    </camelContext> 

The problem I have is this. How can I dynamically inject bean with id "a1"
into the route instance "route1" bean with id "a2" into "route2" and so on.
Hardcoding the bean name or the class name would mean all the route
instances share the same bean which is not what I want.

Is it possible to create property who's value is the id of the bean and
inject that property? Alternatively, are there headers where you can inject
the bean name? I have seen header for the method name but not the bean name. 

Hope it makes sense.

Souciance



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-bean-name-injection-tp5786108.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic bean name injection

Posted by Matt Sicker <bo...@gmail.com>.
Or https://camel.apache.org/message-endpoint.html for the toD() options.

On 8 August 2016 at 17:07, Vitalii Tymchyshyn <vi...@tym.im> wrote:

> Well, the valid options are listed here:
> http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
>
> Нд, 7 серп. 2016 о 14:21 souciance <so...@gmail.com>
> пише:
>
> > Hi Matt,
> >
> > I was unsure if you could inject the id from a header like the example
> you
> > show. I'll give it a try and if it works then that would a be great
> > solution
> > and would reduce quit a lot of code. Thanks for the help.
> >
> >
> >
> > --
> > View this message in context:
> > http://camel.465427.n5.nabble.com/Dynamic-bean-name-
> injection-tp5786108p5786128.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Dynamic bean name injection

Posted by Vitalii Tymchyshyn <vi...@tym.im>.
Well, the valid options are listed here:
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html

Нд, 7 серп. 2016 о 14:21 souciance <so...@gmail.com> пише:

> Hi Matt,
>
> I was unsure if you could inject the id from a header like the example you
> show. I'll give it a try and if it works then that would a be great
> solution
> and would reduce quit a lot of code. Thanks for the help.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Dynamic-bean-name-injection-tp5786108p5786128.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Dynamic bean name injection

Posted by Matt Sicker <bo...@gmail.com>.
The whole list of things you can use for variable substitution are listed
here:
https://camel.apache.org/simple.html

On 7 August 2016 at 13:21, souciance <so...@gmail.com>
wrote:

> Hi Matt,
>
> I was unsure if you could inject the id from a header like the example you
> show. I'll give it a try and if it works then that would a be great
> solution
> and would reduce quit a lot of code. Thanks for the help.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Dynamic-bean-name-injection-tp5786108p5786128.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Dynamic bean name injection

Posted by souciance <so...@gmail.com>.
Hi Matt,

I was unsure if you could inject the id from a header like the example you
show. I'll give it a try and if it works then that would a be great solution
and would reduce quit a lot of code. Thanks for the help.



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-bean-name-injection-tp5786108p5786128.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic bean name injection

Posted by Matt Sicker <bo...@gmail.com>.
Have you looked at using .toD("bean:foo") where you can use the simple
language syntax within? For example, if you have a header named "beanId"
which has your bean name, then you could use .toD("bean:${header.beanId}").

On 7 August 2016 at 12:02, souciance <so...@gmail.com>
wrote:

> Don't have the  code near me,  but basically they are if the pattern:
>
> from()...
> processor()..
> to()..
>
> I want to replace the processor with a bean call e.g.
> bean({{"beanName/beanId"}}
>
> Each route instance needs to refer to a different bean hence the need to
> inject the bean name dynamically or via a property inside a header.
>
> Den 7 aug. 2016 6:26 em skrev "Ranx [via Camel]" <
> ml-node+s465427n5786123h76@n5.nabble.com>:
>
> > What do the routes look like?
> >
> > On Sun, Aug 7, 2016 at 8:50 AM, souciance <[hidden email]
> > <http:///user/SendEmail.jtp?type=node&node=5786123&i=0>>
> > wrote:
> >
> > > Hello,
> > >
> > > I am in the middle of refactoring several routes into a template route.
> > We
> > > have some beans in our blueprint xml (use to configure the camelcontext
> > -
> > > rest is java dsl) like this:
> > >
> > > <bean id="a1" class="com.home.MyA1Bean"/>
> > > <bean id="a2" class="com.home.MyA2Bean"/>
> > > <bean id="a3" class="com.home.MyA3Bean"/>
> > > <bean id="a4" class="com.home.MyA4Bean"/>
> > > <bean id="a5" class="com.home.MyA5Bean"/>
> > >
> > > The route references look similar to:
> > >   <bean id="route1" class="com.home.route">
> > >         <property........./>
> > >     </bean>
> > >   <bean id="route2" class="com.home.route">
> > >         <property........./>
> > >     </bean>
> > >   <bean id="route3" class="com.home.route">
> > >         <property........./>
> > >     </bean>
> > >   <bean id="route4" class="com.home.route">
> > >         <property........./>
> > >     </bean>
> > >   <bean id="route5" class="com.home.route">
> > >         <property........./>
> > >     </bean>
> > >
> > > Then in the camelcontext:
> > > <camelContext id="context" xmlns="http://camel.apache.
> > org/schema/blueprint
> > > ">
> > >         <routeBuilder ref="route1"/>
> > >         <routeBuilder ref="route2"/>
> > >         <routeBuilder ref="route3"/>
> > >         <routeBuilder ref="route4"/>
> > >         <routeBuilder ref="route5"/>
> > >     </camelContext>
> > >
> > > The problem I have is this. How can I dynamically inject bean with id
> > "a1"
> > > into the route instance "route1" bean with id "a2" into "route2" and so
> > on.
> > > Hardcoding the bean name or the class name would mean all the route
> > > instances share the same bean which is not what I want.
> > >
> > > Is it possible to create property who's value is the id of the bean and
> > > inject that property? Alternatively, are there headers where you can
> > inject
> > > the bean name? I have seen header for the method name but not the bean
> > > name.
> > >
> > > Hope it makes sense.
> > >
> > > Souciance
> > >
> > >
> > >
> > > --
> > > View this message in context: http://camel.465427.n5.nabble.
> > > com/Dynamic-bean-name-injection-tp5786108.html
> > > Sent from the Camel - Users mailing list archive at Nabble.com.
> > >
> >
> >
> > ------------------------------
> > If you reply to this email, your message will be added to the discussion
> > below:
> > http://camel.465427.n5.nabble.com/Dynamic-bean-name-
> > injection-tp5786108p5786123.html
> > To start a new topic under Camel - Users, email
> > ml-node+s465427n465428h31@n5.nabble.com
> > To unsubscribe from Dynamic bean name injection, click here
> > <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=
> unsubscribe_by_code&node=5786108&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aU
> BnbWFpbC5jb218NTc4NjEwOHwxNTMyOTExNjU2>
> > .
> > NAML
> > <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_
> viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.
> BasicNamespace-nabble.view.web.template.NabbleNamespace-
> nabble.view.web.template.NodeNamespace&breadcrumbs=
> notify_subscribers%21nabble%3Aemail.naml-instant_emails%
> 21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> >
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Dynamic-bean-name-injection-tp5786108p5786126.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Dynamic bean name injection

Posted by souciance <so...@gmail.com>.
Don't have the  code near me,  but basically they are if the pattern:

from()...
processor()..
to()..

I want to replace the processor with a bean call e.g.
bean({{"beanName/beanId"}}

Each route instance needs to refer to a different bean hence the need to
inject the bean name dynamically or via a property inside a header.

Den 7 aug. 2016 6:26 em skrev "Ranx [via Camel]" <
ml-node+s465427n5786123h76@n5.nabble.com>:

> What do the routes look like?
>
> On Sun, Aug 7, 2016 at 8:50 AM, souciance <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=5786123&i=0>>
> wrote:
>
> > Hello,
> >
> > I am in the middle of refactoring several routes into a template route.
> We
> > have some beans in our blueprint xml (use to configure the camelcontext
> -
> > rest is java dsl) like this:
> >
> > <bean id="a1" class="com.home.MyA1Bean"/>
> > <bean id="a2" class="com.home.MyA2Bean"/>
> > <bean id="a3" class="com.home.MyA3Bean"/>
> > <bean id="a4" class="com.home.MyA4Bean"/>
> > <bean id="a5" class="com.home.MyA5Bean"/>
> >
> > The route references look similar to:
> >   <bean id="route1" class="com.home.route">
> >         <property........./>
> >     </bean>
> >   <bean id="route2" class="com.home.route">
> >         <property........./>
> >     </bean>
> >   <bean id="route3" class="com.home.route">
> >         <property........./>
> >     </bean>
> >   <bean id="route4" class="com.home.route">
> >         <property........./>
> >     </bean>
> >   <bean id="route5" class="com.home.route">
> >         <property........./>
> >     </bean>
> >
> > Then in the camelcontext:
> > <camelContext id="context" xmlns="http://camel.apache.
> org/schema/blueprint
> > ">
> >         <routeBuilder ref="route1"/>
> >         <routeBuilder ref="route2"/>
> >         <routeBuilder ref="route3"/>
> >         <routeBuilder ref="route4"/>
> >         <routeBuilder ref="route5"/>
> >     </camelContext>
> >
> > The problem I have is this. How can I dynamically inject bean with id
> "a1"
> > into the route instance "route1" bean with id "a2" into "route2" and so
> on.
> > Hardcoding the bean name or the class name would mean all the route
> > instances share the same bean which is not what I want.
> >
> > Is it possible to create property who's value is the id of the bean and
> > inject that property? Alternatively, are there headers where you can
> inject
> > the bean name? I have seen header for the method name but not the bean
> > name.
> >
> > Hope it makes sense.
> >
> > Souciance
> >
> >
> >
> > --
> > View this message in context: http://camel.465427.n5.nabble.
> > com/Dynamic-bean-name-injection-tp5786108.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/Dynamic-bean-name-
> injection-tp5786108p5786123.html
> To start a new topic under Camel - Users, email
> ml-node+s465427n465428h31@n5.nabble.com
> To unsubscribe from Dynamic bean name injection, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5786108&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NTc4NjEwOHwxNTMyOTExNjU2>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-bean-name-injection-tp5786108p5786126.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic bean name injection

Posted by Brad Johnson <br...@mediadriver.com>.
What do the routes look like?

On Sun, Aug 7, 2016 at 8:50 AM, souciance <so...@gmail.com>
wrote:

> Hello,
>
> I am in the middle of refactoring several routes into a template route. We
> have some beans in our blueprint xml (use to configure the camelcontext -
> rest is java dsl) like this:
>
> <bean id="a1" class="com.home.MyA1Bean"/>
> <bean id="a2" class="com.home.MyA2Bean"/>
> <bean id="a3" class="com.home.MyA3Bean"/>
> <bean id="a4" class="com.home.MyA4Bean"/>
> <bean id="a5" class="com.home.MyA5Bean"/>
>
> The route references look similar to:
>   <bean id="route1" class="com.home.route">
>         <property........./>
>     </bean>
>   <bean id="route2" class="com.home.route">
>         <property........./>
>     </bean>
>   <bean id="route3" class="com.home.route">
>         <property........./>
>     </bean>
>   <bean id="route4" class="com.home.route">
>         <property........./>
>     </bean>
>   <bean id="route5" class="com.home.route">
>         <property........./>
>     </bean>
>
> Then in the camelcontext:
> <camelContext id="context" xmlns="http://camel.apache.org/schema/blueprint
> ">
>         <routeBuilder ref="route1"/>
>         <routeBuilder ref="route2"/>
>         <routeBuilder ref="route3"/>
>         <routeBuilder ref="route4"/>
>         <routeBuilder ref="route5"/>
>     </camelContext>
>
> The problem I have is this. How can I dynamically inject bean with id "a1"
> into the route instance "route1" bean with id "a2" into "route2" and so on.
> Hardcoding the bean name or the class name would mean all the route
> instances share the same bean which is not what I want.
>
> Is it possible to create property who's value is the id of the bean and
> inject that property? Alternatively, are there headers where you can inject
> the bean name? I have seen header for the method name but not the bean
> name.
>
> Hope it makes sense.
>
> Souciance
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Dynamic-bean-name-injection-tp5786108.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>