You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Camel Guy <ca...@devguy.com> on 2015/10/20 05:14:18 UTC

Re: Register a new datasource from a route

A similar question was asked on Stack Overflow two months ago. A solution
is posited by the author who also made a suggestion for making this use
case easier.

http://stackoverflow.com/questions/31604721/using-a-custom-registry-in-a-camel-application

On Thu, Feb 5, 2015 at 7:46 AM, Camel Guy <ca...@devguy.com> wrote:

> I see this is fixed in 15.0. I can use the snapshot but how do I use this
> feature?
>
> By the way, this is my solution for IMO a shortcoming in Camel (after
> using it for a year) - the inability to pass objects to consumers except
> via essentially static beans or something like ehcache. I'm using addRoute
> at runtime with dynamically generated from Uris. If you need to pass
> something more complex than a sting to a consumer, and it changes at
> runtime, times are hard.
>
> Thanks,
>
> cg
>
>
>
> On Thursday, November 20, 2014, Willem Jiang <wi...@gmail.com>
> wrote:
>
>> Camel look up the DataSource object from the camel context registry.
>> If you can change the registry dynamically, you can change the data
>> source for the camel-jdbc component just as you said in the first mail.
>>
>> The key point is you need to replace the old CamelContext Registry by a
>> new CompositeRegistry just as CAMEL-8048[1] does.
>>
>> [1]https://issues.apache.org/jira/browse/CAMEL-8048
>>
>> --
>> Willem Jiang
>>
>> Red Hat, Inc.
>> Web: http://www.redhat.com
>> Blog: http://willemjiang.blogspot.com (English)
>> http://jnn.iteye.com (Chinese)
>> Twitter: willemjiang
>> Weibo: 姜宁willem
>>
>>
>>
>> On November 21, 2014 at 4:52:41 AM, Camel Guy (camel@devguy.com) wrote:
>> > Thanks Willem.
>> >
>> > I can make that work! It's just a headache to get a new data source
>> > instance initialized with data that is in Exchange. (Very dynamic data
>> > source..)
>> >
>> > Maybe I should instead be asking for the ability to pass a datasource
>> > to the jdbc component via a header.
>> >
>> > On Wed, Nov 19, 2014 at 11:07 PM, Willem Jiang wrote:
>> > > You can define a factory bean to instantiate the data source.
>> > > When the object export with the name A, camel can look it up from the
>> Spring application
>> > context.
>> > >
>> > > --
>> > > Willem Jiang
>> > >
>> > > Red Hat, Inc.
>> > > Web: http://www.redhat.com
>> > > Blog: http://willemjiang.blogspot.com (English)
>> > > http://jnn.iteye.com (Chinese)
>> > > Twitter: willemjiang
>> > > Weibo: 姜宁willem
>> > >
>> > >
>> > >
>> > > On November 20, 2014 at 1:21:38 PM, Camel Guy (camel@devguy.com)
>> wrote:
>> > >> Hello,
>> > >>
>> > >> I was wondering if a route could invoke a bean (or run, say, a groovy
>> > >> script) that registered a new datasource.
>> > >>
>> > >> Something like:
>> > >>
>> > >> route ::
>> > >> 1) Instantiate datasource
>> > >> 2) Add datasource instance to the registry under key A
>> > >> 3) recipientList("jdbc:A?...")
>> > >>
>> > >> This datasource needs to be created long after Camel starts up.
>> > >>
>> > >> I'm using Spring XML.
>> > >>
>> > >>
>> > >> Thank you,
>> > >> ~cg
>> > >>
>> > >
>> >
>>
>>