|
How do you connect a Datasource to a Cluster ? |
|
Written by F.Marchioni
|
|
JBoss recipe of the day
We'll examine two popular Database: Oracle and MySQL
Oracle cluster (RAC)
Oracle RAC allows multiple computers to run the Oracle RDBMS software simultaneously while accessing a single database thus providing a clustered database.
In order to benefit from Oracle RAC features like fault tolerance and load balancing all you have to do is configuring the connection url with the list of Oracle hosts which belongs to the cluster.
In this example we are configuring our datasource to connect to a RAC made up of host1 and host2:
<connection-url>
jdbc:oracle:thin:@(description=(address_list=(load_balance=on)(failover=on) (address=(protocol=tcp)(host=host1)(port=1521))(address=(protocol=tcp)(host=host2)(port=1521)))(connect_data=(service_name=xxxxsid)(failover_mode=(type=select)(method=basic))))
</connection-url>
My SQL cluster
MySQL Cluster is a real-time open source transactional database designed for fast, always-on access to data under high throughput conditions.
In order to achieve load-balancing and failover across MySQL cluster you need to modify your jdbc Connection string adding the "loadbalance" keyword
to do load-balancing across the SQL nodes in MySQL Cluster, you would use a different JDBC connection string with the "loadbalance" keyword added
<connection-url>
jdbc:mysql:loadbalance://host-1,host-2,...host-n/database?loadBalanceBlacklistTimeout=5000
</connection-url>
Notice the "loadBalanceBlacklistTimeout" adds the needed feature that failed connections in a connection pool are put aside for the specified time, and only working connections are utilized. This parameter is essential for proper failover.
|