Restcomm JDBC Resource Adapter Несколько источников данных

Я использую адаптер ресурсов Jdbc 7.1.15 в моем SBB. Это хорошо работает с одним источником данных. Теперь у меня есть требование поговорить со вторым источником данных из моего SBB, но я не смог найти способ сделать это.

Я попытался обновить resource-adapter-jar.xml в ресурсах /jdbc/ra/src/main/resources/META-INF/. добавив другое свойство конфигурации для 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 для использования двух или более источников данных одновременно?

0 ответов

Чтобы иметь несколько источников данных для адаптера ресурсов Restcomm SLEE Jdbc, необходимо сначала изменить файлы resource-adapter-jar.xml и deploy-config.xml в restcomm-slee-ra-jdbc и restcomm-slee-ra- проекты jdbc-DU соответственно. Вот пример файла resource-adapter-jar.xml, в котором определены два JdbcResourceAdaptors. Один для каждого источника данных.

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

Затем обновите standalone.xml для сервера приложений WildFly (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. В файле sbb-jar.xml приложения JAIN-SLEE настройте каждый 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.

Надеюсь это поможет.

Другие вопросы по тегам