Restcomm JDBC Resource Adaptor Multiple Datasources

118 views Asked by At

I am using Jdbc resource adaptor 7.1.15 in my SBB. It is working well with single Datasource. Now I have a requirement to talk to a second datasource from inside my SBB, but I couldn't find a way to do that.

I tried updating resource-adaptor-jar.xml in resources/jdbc/ra/src/main/resources/META-INF/. by adding another config property for DATASOURCE_JNDI_NAME.like below

<resource-adaptor ignore-ra-type-event-type-check="True">

    <resource-adaptor-name>JdbcResourceAdaptor</resource-adaptor-name>
    <resource-adaptor-vendor>org.restcomm</resource-adaptor-vendor>
    <resource-adaptor-version>1.0</resource-adaptor-version>

    <resource-adaptor-type-ref>
        <resource-adaptor-type-name>JDBCResourceAdaptorType</resource-adaptor-type-name>
        <resource-adaptor-type-vendor>org.restcomm</resource-adaptor-type-vendor>
        <resource-adaptor-type-version>1.0</resource-adaptor-type-version>
    </resource-adaptor-type-ref>

    <resource-adaptor-classes>
        <resource-adaptor-class>
            <resource-adaptor-class-name>
                org.restcomm.slee.resource.jdbc.JdbcResourceAdaptor
            </resource-adaptor-class-name>
        </resource-adaptor-class>
    </resource-adaptor-classes>

    <config-property>
        <config-property-name>DATASOURCE_JNDI_NAME</config-property-name>
        <config-property-type>java.lang.String</config-property-type>
        <config-property-value>java:/ExampleDS</config-property-value>    
    </config-property>
            <config-property>
        <config-property-name>DATASOURCE_JNDI_NAME</config-property-name>
        <config-property-type>java.lang.String</config-property-type>
        <config-property-value>java:/ExampleDS_2</config-property-value>    
    </config-property>
    <config-property>
        <config-property-name>EXECUTOR_SERVICE_THREADS</config-property-name>
        <config-property-type>java.lang.Integer</config-property-type>
        <config-property-value>4</config-property-value>
    </config-property>

    <config-property>
        <config-property-name>RA_SBB_INTERFACE_CONNECTION_GETTERS_ON</config-property-name>
        <config-property-type>java.lang.Boolean</config-property-type>
        <config-property-value>true</config-property-value>
    </config-property>

</resource-adaptor>

but as soon as I deploy it I get deploy errors. My question is, Is there a way to configure jdbc RA to use two or more Datasources at the same time?

1

There are 1 answers

0
Grant Blaise O'Reilly On

In order to have multiple data sources for the Restcomm SLEE Jdbc resource adaptor you need to firstly change your resource-adaptor-jar.xml and deploy-config.xml files in the restcomm-slee-ra-jdbc and restcomm-slee-ra-jdbc-DU projects, respectively. Here is an example of the resource-adaptor-jar.xml where two JdbcResourceAdaptors are defined. One for each data source.

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE resource-adaptor-jar PUBLIC "-//Sun Microsystems, Inc.//DTD JAIN SLEE Resource Adaptor 1.1//EN" "http://java.sun.com/dtd/slee-resource-adaptor-jar_1_1.dtd">

<resource-adaptor-jar>

    <resource-adaptor ignore-ra-type-event-type-check="True">

        <resource-adaptor-name>JdbcResourceAdaptor</resource-adaptor-name>
        <resource-adaptor-vendor>org.restcomm</resource-adaptor-vendor>
        <resource-adaptor-version>1.0</resource-adaptor-version>

        <resource-adaptor-type-ref>
            <resource-adaptor-type-name>JDBCResourceAdaptorType</resource-adaptor-type-name>
            <resource-adaptor-type-vendor>org.restcomm</resource-adaptor-type-vendor>
            <resource-adaptor-type-version>1.0</resource-adaptor-type-version>
        </resource-adaptor-type-ref>

        <resource-adaptor-classes>
            <resource-adaptor-class>
                <resource-adaptor-class-name>
                    org.restcomm.slee.resource.jdbc.JdbcResourceAdaptor
                </resource-adaptor-class-name>
            </resource-adaptor-class>
        </resource-adaptor-classes>

        <config-property>
              <config-property-name>DATASOURCE_JNDI_NAME</config-property-name>
                  <config-property-type>java.lang.String</config-property-type>
                  <config-property-value>java:/STATS_DS</config-property-value>    
                </config-property>

        <config-property>
            <config-property-name>EXECUTOR_SERVICE_THREADS</config-property-name>
            <config-property-type>java.lang.Integer</config-property-type>
            <config-property-value>4</config-property-value>
        </config-property>

        <config-property>
            <config-property-name>RA_SBB_INTERFACE_CONNECTION_GETTERS_ON</config-property-name>
            <config-property-type>java.lang.Boolean</config-property-type>
            <config-property-value>true</config-property-value>
        </config-property>

    </resource-adaptor>

    <resource-adaptor ignore-ra-type-event-type-check="True">

        <resource-adaptor-name>JdbcResourceAdaptor2</resource-adaptor-name>
        <resource-adaptor-vendor>org.restcomm</resource-adaptor-vendor>
        <resource-adaptor-version>1.0</resource-adaptor-version>

        <resource-adaptor-type-ref>
            <resource-adaptor-type-name>JDBCResourceAdaptorType</resource-adaptor-type-name>
            <resource-adaptor-type-vendor>org.restcomm</resource-adaptor-type-vendor>
            <resource-adaptor-type-version>1.0</resource-adaptor-type-version>
        </resource-adaptor-type-ref>

        <resource-adaptor-classes>
            <resource-adaptor-class>
                <resource-adaptor-class-name>
                    org.restcomm.slee.resource.jdbc.JdbcResourceAdaptor
                </resource-adaptor-class-name>
            </resource-adaptor-class>
        </resource-adaptor-classes>

        <config-property>
              <config-property-name>DATASOURCE_JNDI_NAME</config-property-name>
                  <config-property-type>java.lang.String</config-property-type>
                  <config-property-value>java:/AppConfigDS</config-property-value>    
                </config-property>                

        <config-property>
            <config-property-name>EXECUTOR_SERVICE_THREADS</config-property-name>
            <config-property-type>java.lang.Integer</config-property-type>
            <config-property-value>4</config-property-value>
        </config-property>

        <config-property>
            <config-property-name>RA_SBB_INTERFACE_CONNECTION_GETTERS_ON</config-property-name>
            <config-property-type>java.lang.Boolean</config-property-type>
            <config-property-value>true</config-property-value>
        </config-property>

    </resource-adaptor>        

</resource-adaptor-jar>

Then the deploy-config.xml needs to be updated with the entity names. In my case I created the entity names JDBCRA and JDBCRA-Config. JDBCRA would be the data source for the application statistics and JDBCRA-Config would be the data source for the application configuration.

    <?xml version="1.0" encoding="UTF-8"?>
<deploy-config>
    <ra-entity
        resource-adaptor-id="ResourceAdaptorID[name=JdbcResourceAdaptor,vendor=org.restcomm,version=1.0]"
        entity-name="JDBCRA">
        <properties/>
        <ra-link name="JDBCRA" />
    </ra-entity>
    <ra-entity
        resource-adaptor-id="ResourceAdaptorID[name=JdbcResourceAdaptor,vendor=org.restcomm,version=1.0]"
        entity-name="JDBCRA-CONFIG">
        <properties/>
        <ra-link name="JDBCRA-CONFIG" />
    </ra-entity>        
</deploy-config>

Then update the standalone.xml for the WildFly App server (restcomm-slee-7.1.83.87-wildfly-10.1.0.Final) to include the two data sources:

 <subsystem xmlns="urn:jboss:domain:datasources:4.0">
  ...
                <datasource jndi-name="java:/STATS_DS" pool-name="STATS_DS">
                    <connection-url>jdbc:postgresql://localhost:5432/appstats</connection-url>
                    <driver>postgres</driver>
                    <pool>
                        <min-pool-size>20</min-pool-size>
                        <initial-pool-size>50</initial-pool-size>
                        <max-pool-size>150</max-pool-size>
                    </pool>
                    <security>
                        <user-name>user</user-name>
                        <password>password</password>
                    </security>
                </datasource>
                <datasource jndi-name="java:/AppConfigDS" pool-name="AppConfigDS">
                    <connection-url>jdbc:postgresql://localhost:5432/appconfig</connection-url>
                    <driver-class>org.postgresql.Driver</driver-class>
                    <driver>postgres</driver>
                    <security>
                        <user-name>username</user-name>
                        <password>password</password>
                    </security>
                </datasource>
 ...
            </datasources>
        </subsystem>  

Secondly, in your JAIN-SLEE application define two SBBs, namely StatsDataSourceSBB and ConfigDataSourceSBB. In the sbb-jar.xml of the JAIN-SLEE application configure each SBB as follows:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE sbb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD JAIN SLEE SBB 1.1//EN"
                         "http://java.sun.com/dtd/slee-sbb-jar_1_1.dtd">
<sbb-jar>
    <sbb id="MainSbb">
        <description>Example</description>
        <sbb-name>MainSbb</sbb-name>
        <sbb-vendor>au.com.example</sbb-vendor>
        <sbb-version>1.0.0</sbb-version>
        <sbb-alias>MainSbb</sbb-alias>

                <sbb-ref>
                    <sbb-name>StatsDataSourceSBB</sbb-name>
                    <sbb-vendor>au.com.example</sbb-vendor>
                    <sbb-version>1.0.0</sbb-version>
                    <sbb-alias>StatsDataSourceSBB</sbb-alias>
                </sbb-ref>  

                <sbb-ref>
                    <sbb-name>ConfigDataSourceSBB</sbb-name>
                    <sbb-vendor>au.com.example</sbb-vendor>
                    <sbb-version>1.0.0</sbb-version>
                    <sbb-alias>ConfigDataSourceSBB</sbb-alias>
                </sbb-ref>                  
...
    </sbb>
        <sbb>
           <description/>
           <sbb-name>StatsDataSourceSBB</sbb-name>
           <sbb-vendor>au.com.vasx</sbb-vendor>
           <sbb-version>1.0.0</sbb-version>
           <sbb-classes>
               <sbb-abstract-class>
                   <sbb-abstract-class-name>au.com.example.app.sbb.statsdata.StatsDataSourceSBB</sbb-abstract-class-name>             
               </sbb-abstract-class>   
                <sbb-local-interface>
                            <sbb-local-interface-name>au.com.example.app.sbb.statsdata.StatsDataSourceSbbLocalObject</sbb-local-interface-name>
                </sbb-local-interface>        
           </sbb-classes>
           <event event-direction="Receive" initial-event="False">
               <event-name>SimpleJdbcTaskResultEvent</event-name>
               <event-type-ref>
                   <event-type-name>SimpleJdbcTaskResultEvent</event-type-name>
                   <event-type-vendor>org.restcomm</event-type-vendor>
                   <event-type-version>1.0</event-type-version>
               </event-type-ref>
           </event>
           <event event-direction="Receive" initial-event="False">
               <event-name>JdbcTaskExecutionThrowableEvent</event-name>
               <event-type-ref>
                   <event-type-name>JdbcTaskExecutionThrowableEvent</event-type-name>
                   <event-type-vendor>org.restcomm</event-type-vendor>
                   <event-type-version>1.0</event-type-version>
               </event-type-ref>
           </event>         
           <resource-adaptor-type-binding>
               <resource-adaptor-type-ref>
                   <resource-adaptor-type-name>JDBCResourceAdaptorType</resource-adaptor-type-name>
                   <resource-adaptor-type-vendor>org.restcomm</resource-adaptor-type-vendor>
                   <resource-adaptor-type-version>1.0</resource-adaptor-type-version>
               </resource-adaptor-type-ref>
               <activity-context-interface-factory-name>slee/ra/jdbc/1.0/acifactory</activity-context-interface-factory-name>
               <resource-adaptor-entity-binding>
                   <resource-adaptor-object-name>slee/ra/jdbc/1.0/sbbinterface</resource-adaptor-object-name>
                   <resource-adaptor-entity-link>JDBCRA</resource-adaptor-entity-link>
               </resource-adaptor-entity-binding>
           </resource-adaptor-type-binding>       

       </sbb>   
       <sbb>
           <description/>
           <sbb-name>ConfigDataSourceSBB</sbb-name>
           <sbb-vendor>au.com.vasx</sbb-vendor>
           <sbb-version>1.0.0</sbb-version>
           <sbb-classes>
               <sbb-abstract-class>
                   <sbb-abstract-class-name>au.com.example.app.sbb.config.ConfigDataSourceSBB</sbb-abstract-class-name>             
               </sbb-abstract-class>   
                <sbb-local-interface>
                            <sbb-local-interface-name>au.com.example.app.sbb.config.ConfigDataSourceSbbLocalObject</sbb-local-interface-name>
                </sbb-local-interface>        
           </sbb-classes>
           <event event-direction="Receive" initial-event="False">
               <event-name>SimpleJdbcTaskResultEvent</event-name>
               <event-type-ref>
                   <event-type-name>SimpleJdbcTaskResultEvent</event-type-name>
                   <event-type-vendor>org.restcomm</event-type-vendor>
                   <event-type-version>1.0</event-type-version>
               </event-type-ref>
           </event>
           <event event-direction="Receive" initial-event="False">
               <event-name>JdbcTaskExecutionThrowableEvent</event-name>
               <event-type-ref>
                   <event-type-name>JdbcTaskExecutionThrowableEvent</event-type-name>
                   <event-type-vendor>org.restcomm</event-type-vendor>
                   <event-type-version>1.0</event-type-version>
               </event-type-ref>
           </event>         
           <resource-adaptor-type-binding>
               <resource-adaptor-type-ref>
                   <resource-adaptor-type-name>JDBCResourceAdaptorType</resource-adaptor-type-name>
                   <resource-adaptor-type-vendor>org.restcomm</resource-adaptor-type-vendor>
                   <resource-adaptor-type-version>1.0</resource-adaptor-type-version>
               </resource-adaptor-type-ref>
               <activity-context-interface-factory-name>slee/ra/jdbc/1.0/acifactory</activity-context-interface-factory-name>
               <resource-adaptor-entity-binding>
                   <resource-adaptor-object-name>slee/ra/jdbc/1.0/sbbinterface</resource-adaptor-object-name>
                   <resource-adaptor-entity-link>JDBCRA-CONFIG</resource-adaptor-entity-link>
               </resource-adaptor-entity-binding>
           </resource-adaptor-type-binding>       

       </sbb>         
</sbb-jar>

That should allow you to define multiple data source to your Restcomm JAIN-SLEE JDBC RA.

Hope this helps.