Restcomm JDBC资源适配器多个数据源

时间:2018-07-13 02:14:11

标签: java restcomm jain-slee

我在SBB中使用Jdbc资源适配器7.1.15。它可以与单个数据源一起很好地工作。 现在,我需要从SBB内部与第二个数据源进行对话,但是我找不到解决方法。

我尝试更新resources / jdbc / ra / src / main / resources / META-INF /中的resource-adaptor-jar.xml。通过为DATASOURCE_JNDI_NAME添加另一个配置属性,如下所示

<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>

,但是一旦我部署它,就会出现部署错误。 我的问题是,是否可以将jdbc RA配置为同时使用两个或多个数据源?

1 个答案:

答案 0 :(得分:0)

为了具有Restcomm SLEE Jdbc资源适配器的多个数据源,您需要首先更改restcomm-slee-ra-jdbc和restcomm-slee中的resource-adaptor-jar.xml和deploy-config.xml文件-ra-jdbc-DU项目。 这是resource-adaptor-jar.xml的示例,其中定义了两个JdbcResourceAdaptor。每个数据源一个。

<?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>

然后,需要使用实体名称更新deploy-config.xml。就我而言,我创建了实体名称JDBCRA和JDBCRA-Config。 JDBCRA将是应用程序统计信息的数据源,而JDBCRA-Config将是应用程序配置的数据源。

    <?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>

然后更新WildFly App服务器的standalone.xml(restcomm-slee-7.1.83.87-wildfly-10.1.0.Final)以包括两个数据源:

 <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>  

第二,在您的JAIN-SLEE应用程序中定义两个SBB,即StatsDataSourceSBB和ConfigDataSourceSBB。在JAIN-SLEE应用程序的sbb-jar.xml中,如下配置每个SBB:

<?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>

这应该允许您为Restcomm JAIN-SLEE JDBC RA定义多个数据源。

希望这会有所帮助。