简体   繁体   English

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

[英]Restcomm JDBC Resource Adaptor Multiple Datasources

I am using Jdbc resource adaptor 7.1.15 in my SBB. 我在SBB中使用Jdbc资源适配器7.1.15。 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. 现在,我需要从SBB内部与第二个数据源进行对话,但是我找不到解决方法。

I tried updating resource-adaptor-jar.xml in resources/jdbc/ra/src/main/resources/META-INF/. 我尝试在resources / jdbc / ra / src / main / resources / META-INF /中更新resource-adaptor-jar.xml。 by adding another config property for DATASOURCE_JNDI_NAME.like below 通过为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>

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? 我的问题是,是否可以将jdbc RA配置为同时使用两个或多个数据源?

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. 为了拥有Restcomm SLEE Jdbc资源适配器的多个数据源,您需要首先更改restcomm-slee-ra-jdbc和restcomm-slee-ra-中的resource-adaptor-jar.xml和deploy-config.xml文件。 jdbc-DU项目分别。 Here is an example of the resource-adaptor-jar.xml where two JdbcResourceAdaptors are defined. 这是resource-adaptor-jar.xml的示例,其中定义了两个JdbcResourceAdaptor。 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. 然后,需要使用实体名称更新deploy-config.xml。 In my case I created the entity names JDBCRA and JDBCRA-Config. 就我而言,我创建了实体名称JDBCRA和JDBCRA-Config。 JDBCRA would be the data source for the application statistics and JDBCRA-Config would be the data source for the application configuration. 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>

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: 然后更新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>  

Secondly, in your JAIN-SLEE application define two SBBs, namely StatsDataSourceSBB and ConfigDataSourceSBB. 其次,在您的JAIN-SLEE应用程序中定义两个SBB,即StatsDataSourceSBB和ConfigDataSourceSBB。 In the sbb-jar.xml of the JAIN-SLEE application configure each SBB as follows: 在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>

That should allow you to define multiple data source to your Restcomm JAIN-SLEE JDBC RA. 这应该允许您为Restcomm JAIN-SLEE JDBC RA定义多个数据源。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM