A high availability Datasource is an abstraction over a list of data sources that provide failover processing between lists of data sources. In Weblogic, we can configure multi-pool which provides us the same functionality.
The configuration of Multi pool sort of thing in JBoss is done in a different way. In Weblogic, we configure multiple data sources and configure them in one multi pool such that when a Datasource fails to connect, the servers use the second Datasource to get a connection.
In JBoss, we don’t need to configure multiple data sources rather we configure the URL’s in one Datasource file like,
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>HADataSource</jndi-name>
<connection-url>jdbc:oracle:thin:@DO0601.nova.oracle.com:1521:DO0601|jdbc:oracle:thin:@DO0602.nova.oracle.com:1521:DO0602</connection-url>
<url-delimiter>|</url-delimiter>
<user-name>drbc777</user-name>
<password>rbc1dev</password>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
The main points to check are the
<connection-url>jdbc:oracle:thin:@DO0601.nova.oracle.com:1521:DO0601|jdbc:oracle:thin:@DO0602.nova.oracle.com:1521:DO0602</connection-url> : Url separated by a delimiter “|”
<url-delimiter>|</url-delimiter> : Holder used as a delimiter
Now, we can test the Datasource from the admin-console. If we need to test the fail over capabilities, then modify the one of the URL and test the connection. You can see an error on command console and connection will be obtained from second URL.
Note: we can use connection.getMetaData().getUrl() , to find which URL is used to get the connection. In this way we can make sure the fail over is working.
More articles to come. Happy coding…
thanks... nice post. for more java examples, visit http://java2novice.com site
ReplyDelete