You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Michael Dewitte <mi...@gmail.com> on 2011/03/31 13:39:53 UTC

multiple databases used in mybatis or ibatis in one route

Hi,

I finally succeeded using MyBatis in a route with camel 2.7.0 deployed on
Karaf (servicemix in fact).
But what I'd like now is to be able to use 2 different databases in the same
route.
I know that I can define different databases in MyBatis, but is it possible
to configure two instances of the MyBatis component for Camel in the same
route, each one pointing to a different database ?
Or maybe is there another way to use the 2 databases in the same route ? or
use subroutes ?

Thanks for your help,

Mike

Re: destoring sequence of camel context and beans

Posted by Willem Jiang <wi...@gmail.com>.
On 4/1/11 6:20 PM, ext2 wrote:
> Thanks,Claus:
>
> The real problem is  spring doesn't understand the camel's xml schema. For
> example:
> 	<from uri="bean:beanId....">
> the camel processor may dependency on a spring bean by the beanId; but the
> spring know nothing about this;
>
> So I am wondering if camel has  carefully deal the destroy life cycle? I try
> to check the source code of camel, but still know nothing about this;
>
As the bean is create by the spring, camel should not get involved with it.
You can add the depends-on in your camel context like this

   <camelContext id="camel" 
xmlns="http://camel.apache.org/schema/spring" depends-on="mybean">
     <route>
       <from uri="bean:mybean">
       ...
     <route/>
   </camelContext>
>
>
> ============================================================================
> On Fri, Apr 1, 2011 at 9:20 AM, ext2<xu...@tongtech.com>  wrote:
>>
>>
>> Hi:
>>         With spring, caml processors may depend on many beans. Could camel
>> will ensure the camelcontext will be destroy before all the dependencies
>> while spring context is destroy?
>>
>>
>
> Check the spring documentation how it allows you to configure ordering
> between beans. Thats normally the depends-on attribute you can use.
>
>>
>>
>
>
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Connect at CamelOne May 24-26
The Open Source Integration Conference
http://camelone.com

Re: destoring sequence of camel context and beans

Posted by ext2 <xu...@tongtech.com>.
Thanks,Claus:

The real problem is  spring doesn't understand the camel's xml schema. For
example:
	<from uri="bean:beanId...."> 
the camel processor may dependency on a spring bean by the beanId; but the
spring know nothing about this;

So I am wondering if camel has  carefully deal the destroy life cycle? I try
to check the source code of camel, but still know nothing about this;



============================================================================
On Fri, Apr 1, 2011 at 9:20 AM, ext2 <xu...@tongtech.com> wrote:
>
>
> Hi:
>        With spring, caml processors may depend on many beans. Could camel
> will ensure the camelcontext will be destroy before all the dependencies
> while spring context is destroy?
>
>

Check the spring documentation how it allows you to configure ordering
between beans. Thats normally the depends-on attribute you can use.

>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/



Re: destoring sequence of camel context and beans

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Apr 1, 2011 at 9:20 AM, ext2 <xu...@tongtech.com> wrote:
>
>
> Hi:
>        With spring, caml processors may depend on many beans. Could camel
> will ensure the camelcontext will be destroy before all the dependencies
> while spring context is destroy?
>
>

Check the spring documentation how it allows you to configure ordering
between beans. Thats normally the depends-on attribute you can use.

>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: multiple databases used in mybatis or ibatis in one route

Posted by Michael Dewitte <mi...@gmail.com>.
Hello,

thanks to Claus and Richard, it worked !

So, to further help anyone who would have the same need : I wanted to be
able to use MyBatis pointing to 2 different datasources in the same route. I
use Camel 2.7.0 on ServiceMix (trunk).

Using the spring dsl, my configuration was :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ctx="
http://www.springframework.org/schema/context"
xmlns:camel="http://camel.apache.org/schema/spring" xmlns:osgix="
http://www.springframework.org/schema/osgi-compendium"
xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
       http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
       http://www.springframework.org/schema/osgi-compendium
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
">

<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from URI="timer://SynchroDB?period=30000"/>
<to uri="mybatis:selectDataToTransfert?statementType=SelectList" />   <!--
retrieve the list of ID to synchronise -->
                        <split>
                           <simple>${body}</simple>
                           <to uri="log:events" />
                           <to
uri="mybatis:selectDataContentToTransfert?statementType=SelectOne" /> <!--
retrieve the datato transfert -->
                           <to
uri="mybatis2:registerInbound?statementType=Insert" />
                        </split>
</route>
</camel:camelContext>
    <bean id="mybatis2"
class="org.apache.camel.component.mybatis.MyBatisComponent">
       <property name="configurationUri"
value="SqlMapConfig_destination.xml"/>
    </bean>
</beans>


Hope it'll be helpfull to someone !

Mike


2011/4/1 Michael Dewitte <mi...@gmail.com>

> Thnaks to you, Claus and Richard for this fast and extensive help ! I'll
> give it a try today !
>
> Thx,
>
> Mike
>
>
>
> 2011/3/31 Richard Kettelerij <ri...@gmail.com>
>
>> To use this component in your route use:
>>
>>       from("mybatis2:selectFoo").to("...");
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/multiple-databases-used-in-mybatis-or-ibatis-in-one-route-tp4273206p4274145.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: multiple databases used in mybatis or ibatis in one route

Posted by Michael Dewitte <mi...@gmail.com>.
Thnaks to you, Claus and Richard for this fast and extensive help ! I'll
give it a try today !

Thx,

Mike



2011/3/31 Richard Kettelerij <ri...@gmail.com>

> To use this component in your route use:
>
>       from("mybatis2:selectFoo").to("...");
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/multiple-databases-used-in-mybatis-or-ibatis-in-one-route-tp4273206p4274145.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

destoring sequence of camel context and beans

Posted by ext2 <xu...@tongtech.com>.

Hi:
	With spring, caml processors may depend on many beans. Could camel
will ensure the camelcontext will be destroy before all the dependencies
while spring context is destroy?
	



Re: multiple databases used in mybatis or ibatis in one route

Posted by Richard Kettelerij <ri...@gmail.com>.
To use this component in your route use:

       from("mybatis2:selectFoo").to("...");


--
View this message in context: http://camel.465427.n5.nabble.com/multiple-databases-used-in-mybatis-or-ibatis-in-one-route-tp4273206p4274145.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: multiple databases used in mybatis or ibatis in one route

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah you should be able to declare a 2nd mybatis component and
configure it to use a different mybatis configuration file.

<bean id="mybatis2" class="...MyBatisComponent">
   <!-- configure a property with the configuration file to use -->
</bean>



On Thu, Mar 31, 2011 at 1:39 PM, Michael Dewitte
<mi...@gmail.com> wrote:
> Hi,
>
> I finally succeeded using MyBatis in a route with camel 2.7.0 deployed on
> Karaf (servicemix in fact).
> But what I'd like now is to be able to use 2 different databases in the same
> route.
> I know that I can define different databases in MyBatis, but is it possible
> to configure two instances of the MyBatis component for Camel in the same
> route, each one pointing to a different database ?
> Or maybe is there another way to use the 2 databases in the same route ? or
> use subroutes ?
>
> Thanks for your help,
>
> Mike
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/