swarm / io.thorntail:如何定义2个xa数据源以及在哪里?

时间:2018-09-30 14:39:18

标签: datasource wildfly-swarm thorntail

我的thorntail / swarm应用程序需要2个xa数据源,但是我不知道在哪里放置相关信息。从我的阅读看来,我需要有一个project-default.yml文件,例如:

 swarm:
  datasources:
    xa-data-sources:
      statsDS:
        driver-name: postgresql
        connection-url: jdbc:postgresql://postgres:5432/stats
        user-name: stats
        password: stats++
      OracleDS:
        driver-name: oracle
        connection-url: jdbc:oracle:thin:@oracle:1521:XE
        user-name: ora
        password: ora++
    jdbc-drivers:
      oracle: 
        driver-class-name: oracle.jdbc.OracleDriver
        xa-datasource-class: oracle.jdbc.xa.client.OracleXADataSource
        driver-module-name: com.oracle
      postgresql:
        driver-class-name: org.postgresql.Driver
        xa-datasource-class: org.postgresql.xa.PGXADataSource
        driver-module-name: org.postgresql

还有一些* -ds.xml文件,在这些* -ds.xml文件中,我找到了一些与project-default.yml中相同的信息。例如,oracle-ds.xml:

<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
    <!-- The datasource is bound into JNDI at this location. We reference this 
        in META-INF/persistence.xml -->
    <xa-datasource
        jndi-name="java:jboss/datasources/oracleDS" pool-name="oracle">
        <xa-datasource-property name="URL">
            jdbc:oracle:thin:@oracle:1521:XE
        </xa-datasource-property>
        <driver>oracle</driver>
        <security>
            <user-name>ora</user-name>
            <password>ora++</password>
        </security>
        <validation>
            <valid-connection-checker
                class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker" />
            <stale-connection-checker
                class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker" />
            <exception-sorter
                class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter" />
        </validation>
    </xa-datasource>
</datasources>

为什么这两个文件中的信息(驱动程序,用户,passwd,URL)相同?

无论如何,这个conf无效:

2018-09-30 14:07:19,377 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 6) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("xa-data-source" => "statsDS")
]) - failure description: "WFLYCTL0155: 'jndi-name' may not be null"

只是完整的postgresql-ds.xml:

<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
    <xa-datasource jndi-name="java:jboss/datasources/statsDS"
        pool-name="PostgresXADS">
        <xa-datasource-property name="URL">
            jdbc:postgresql://postgres:5432/stats
        </xa-datasource-property>
        <driver>postgresql</driver>
    <security>
            <user-name>stats</user-name>
            <password>stats++</password>
        </security>
        <validation>
            <valid-connection-checker
                class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker">
            </valid-connection-checker>
            <exception-sorter
                class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter">
            </exception-sorter>
        </validation>
    </xa-datasource>
</datasources>

如果我不使用project-default.yml,而仅使用* -ds.xml文件,那么我将:

"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.oracle"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.data-source.\"jboss.naming.context.java.jboss.datasources.oracleDS\" is missing [jboss.jdbc-driver.oracle]"]

我可以精确地说,在我的resources / modules / com / oracle / main目录中有一个module.xml和ojdbcxxx.jar。

那么,应该如何在我的项目中使用2个XA数据源? 谢谢...

2 个答案:

答案 0 :(得分:0)

最后,不需要* -ds.xml文件,这些文件中的所有内容都可以位于project-default.yml中。最后,我的project-default.yml看起来像:

swarm:
  datasources:
    xa-data-sources:
      statsDS:
        driver-name: postgresql
        jndi-name: java:jboss/datasources/statsDS
        user-name: stats
        password: stats++
        valid-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker
        exception-sorter-class-name: org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter
        xa-datasource-properties:
          URL: jdbc:postgresql://postgres:5432/stats

      oracleDS:
        driver-name: oracle
        jndi-name: java:jboss/datasources/oracleDS
        user-name: ora
        password: ora++
        valid-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker
        validate-on-match: true
        background-validation: false
        stale-connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker
        exception-sorter-class-name: org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter
        xa-datasource-properties:
          URL: jdbc:oracle:thin:@oracle:1521:XE

    jdbc-drivers:
      oracle: 
        driver-class-name: oracle.jdbc.OracleDriver
        xa-datasource-class: oracle.jdbc.xa.client.OracleXADataSource
        driver-module-name: com.oracle
      postgresql:
        driver-class-name: org.postgresql.Driver
        xa-datasource-class: org.postgresql.xa.PGXADataSource
        driver-module-name: org.postgresql

然后注意在您的资源目录中拥有正确的模块。 就是这样。

希望它可以对某些人有所帮助,因为我发现文档对此有些可怜。

答案 1 :(得分:0)

您快到了。如下配置URL属性:

 xa-datasource-properties:
      URL: 
        value: jdbc:oracle:thin:@oracle:1521:XE

我从以下线程获得了解决方案:https://issues.jboss.org/browse/THORN-1270

我花了一些时间才弄清楚。