Many thanks for the example. This looks quite useful.
How about adding this to the karaf or ops4j docs?
I also think we could support ha-jdbc in pax-jdbc. With a suitable
module there we might be able to reduce the config to just
creating the etc/ha-jdbc-mycluster.xml and installing a feature (on top
of the individual DS config of course).
WDYT?
Christian
On 14.12.2016 16:12, conejo wrote:
Hi JB. You're right.
I think I've got it. I leave this little guide in case anyone is interested.
How to configure a datasource ha-jdbc in karaf:
1.- We assume that we have installed the features: jndi, jdbc,
pax-jdbc-config, pax-jdbc-pool-dbcp2, pax-jdbc-h2 and any pax-jdbc-ddbb
2.- The ha-jdbc bundle is installed: bundle:install -s
wrap:mvn:net.sf.ha-jdbc/ha-jdbc/3.0.3
Note that ha-jdbc is in the repository
https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/
3.- Configure the datasource of the cluster nodes using pax-jdbc-config (in
etc):
org.ops4j.datasource-nodeDS1.cfg
url=jdbc\:h2\:file\:./prueba_db1/prueba
dataSourceName=nodeDS1
osgi.jdbc.driver.name=H2-pool
org.ops4j.datasource-nodeDS2.cfg
url=jdbc\:h2\:file\:./prueba_db2/prueba
dataSourceName=nodeDS2
osgi.jdbc.driver.name=H2-pool
With that we have 2 datasources with jndi url = osgi:service/nodeDS1 y
osgi:service/nodeDS2
4.- A ha-jdbc configuration file (etc/ha-jdbc-mycluster.xml) is defined with
the previous datasources:
<ha-jdbc xmlns="urn:ha-jdbc:cluster:3.0">
<sync id="full">
<property name="fetchSize">1000</property>
</sync>
<cluster default-sync="full" dialect="h2">
<database id="db1" location="osgi:service/nodeDS1">
</database>
<database id="db2" location="osgi:service/nodeDS2">
</database>
</cluster>
</ha-jdbc>
5.- The datasource ha-jdbc is defined using blueprint (it is copied to
deploy, for example):
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
<ext:property-placeholder placeholder-prefix="$["
placeholder-suffix="]"/>
<bean class="net.sf.hajdbc.sql.DataSource" id="haDatasource">
<property name="config"
value="file:///$[karaf.base]/etc/ha-jdbc-mycluster.xml"></property>
<property name="cluster" value="mycluster"></property>
</bean>
<service id="haDS" interface="javax.sql.DataSource"
ref="haDatasource">
<service-properties>
<entry key="osgi.jndi.service.name"
value="pruebaDS"/>
</service-properties>
</service>
</blueprint>
See https://ha-jdbc.github.io/doc.html
--
View this message in context:
http://karaf.922171.n3.nabble.com/HA-JDBC-in-karaf-tp4048999p4049009.html
Sent from the Karaf - User mailing list archive at Nabble.com.
--
Christian Schneider
http://www.liquid-reality.de
Open Source Architect
http://www.talend.com