Wednesday 16 December 2015

Jboss EAP 6.1 Configuration for Auto Reconnecting to DataBase

Jboss EAP 6.1 Configuration for Auto Reconnecting to DataBase 
This is the configuration that we need to include in datasource configuration in JBoss EAP 6.1 if we want the Jboss EAP 6.1 to automatically re-connect to the database in case DB is crased and is restarted.
Otherwise, we will have to restart the jboss application to again reconnect with the DB.

<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLStaleConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<validate-on-match>true</validate-on-match>                      
<use-fast-fail>true</use-fast-fail>                      
</validation>

The following is the live example for Postgres DB:
<datasource jndi-name="java:jboss/datasources/ExampleDB" pool-name="ExampleDB" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/EXAMPLE_DB</connection-url>
                    <driver>postgres</driver>
                    <security>
                        <user-name>postgres</user-name>
                        <password>postgres</password>
                    </security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLStaleConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<validate-on-match>true</validate-on-match>                        
<use-fast-fail>true</use-fast-fail>                        
</validation>
</datasource>

No comments:

Post a Comment