1 Reply Latest reply on Nov 16, 2018 7:10 AM by burcu-kalkan-47367366

    Automatically choose alternate datasource?

    klng

      Hi,

      I'm using mysql replication (master/slave) and want all clients to access the slave server when the master is inaccessible.

      Is there a way to configure jboss datasource such that it automagically uses the alternate datasource when the first one failed?

      Thanks!
      Kai

        • 1. Re: Automatically choose alternate datasource?
          burcu-kalkan-47367366

          Master/Slave configuration is below. Do you know master/master configuration? 

           

          <datasources>
            
          <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
            
          <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
            
          <driver>h2</driver>
            
          <security>
            
          <user-name>sa</user-name>
            
          <password>sa</password>
            
          </security>
            
          </datasource>
            
          <datasource jta="true" jndi-name="java:jboss/datasources/RailbaseLabDS" pool-name="RailbaseLabDS" enabled="true" use-java-context="true" use-ccm="true">
            
          <connection-url>jdbc:mysql://IP1:3306,IP2:3306/DBN?autoreconnect=true</connection-url>
            
          <driver-class>com.mysql.jdbc.Driver</driver-class>
            
          <driver>mysql</driver>
            
          <url-delimiter>|</url-delimiter>
            
          <security>
            
          <user-name>DBN</user-name>
            
          <password>DBN</password>
            
          </security>
            
          <validation>
            
          <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
            
          <check-valid-connection-sql>select 1</check-valid-connection-sql>
            
          <background-validation>true</background-validation>
            
          <background-validation-millis>5000</background-validation-millis>
            
          </validation>
            
          </datasource>
            
          <drivers>
            
          <driver name="h2" module="com.h2database.h2">
            
          <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
            
          </driver>
            
          <driver name="mysql" module="com.mysql">
            
          <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
            
          </driver>
            
          </drivers>
            
          </datasources>