How to enable multiple datasource in camel jdbc endpoint?

1.4k Views Asked by At

I want to enable camel load balancer for multiple datasource. Any one please let me how to enable multiple datasource in camel jdbc endpoint. Thanks in advance!!

Here is my code. Creating multiple datasource in defaultcamelcontext.

        SimpleRegistry simpleregistry = new SimpleRegistry();
        Map<String, Object> ds = new HashMap<String, Object>();
        ds.put("dataSource", mydataSource);
        ds.put("dataSource1", mydataSource1);
        simpleregistry.putAll(ds);

        Camel camel = CamelExtension.get(system);
        DefaultCamelContext defaultCamelContext = camel.context();
        defaultCamelContext.setRegistry(simpleregistry);

My route builder pointing to multiple datasource:

    from("direct:checkUser").setBody(simple("${body}"))
            .loadBalance()
            .failover()
            .to("jdbc:dataSource?resetAutoCommit=false&outputType=SelectList","jdbc:dataSource1?resetAutoCommit=false&outputType=SelectList");

My requirement is if datasource is down my request need to redirect/pick automatically to datasource1. Please let me how to achieve it.

1

There are 1 best solutions below

0
On

Separate the to, so they are individual

from("direct:checkUser").setBody(simple("${body}"))
       .loadBalance().failover()
            .to("jdbc:dataSource?resetAutoCommit=false&outputType=SelectList")
            .to("jdbc:dataSource1?resetAutoCommit=false&outputType=SelectList");