Sunday, June 24, 2018

Using Oracle Connection Pools with ActiveMQ

Following bean entries could be used for creating pooled JDBC connections from an activemq conflagration.
To use Oracle data source add the following to activemq.xml.
 <bean id="oracle-ds" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
    <property name="uRL" value="jdbc:oracle:thin:@192.168.0.86:1521/testdb"/>
    <property name="user" value="asanga"/>
    <property name="password" value="asa"/>
    <property name="connectionCachingEnabled" value="true"/>
<!--    <property name="fastConnectionFailoverEnabled" value="true"/> -->
<!--    <property name="oNSConfiguration" value="nodes=xxx:6200"/> -->
    <property name="connectionCacheProperties">
         <props>
              <prop key="InitialLimit">5</prop>
              <prop key="MinLimit">5</prop>
              <prop key="MaxLimit">10</prop>
        </props>
    </property>
  </bean>
Any other data source property could be added by following the camel casing the method name without "set". For example "setONSConfiguration" becomes "oNSConfiguration" as shown above.



To use Oracle Universal Connection Pool use the following
  <bean id="oracle-ds" class="oracle.ucp.jdbc.PoolDataSourceFactory" factory-method="getPoolDataSource">
    <property name="connectionFactoryClassName" value="oracle.jdbc.pool.OracleDataSource"/>
    <property name="uRL" value="jdbc:oracle:thin:@192.168.0.86:1521/testdb"/>
    <property name="user" value="asanga"/>
    <property name="password" value="asa"/>
<!--     <property name="fastConnectionFailoverEnabled" value="true"/> -->
<!--     <property name="oNSConfiguration" value="nodes=xxxx:6200"/> -->
    <property name="minPoolSize" value="5"/>
    <property name="initialPoolSize" value="5"/>
    <property name="maxPoolSize" value="10"/>
    <property name="connectionProperties">
         <props>
              <prop key="oracle.jdbc.thinForceDNSLoadBalancing">true</prop>
        </props>
    </property>
  </bean>
Enable the persistency with
        <persistenceAdapter>
            <jdbcPersistenceAdapter dataSource="#oracle-ds" lockKeepAlivePeriod="5000">
                 <locker>
                     <lease-database-locker lockAcquireSleepInterval="10000"/>
                </locker>
            </jdbcPersistenceAdapter>
         </persistenceAdapter>