0

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

为什么这两个文件中的信息(驱动程序、用户、密码、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]"]

我可能会准确地说我的资源/模块/com/oracle/main 目录中有一个 module.xml 和 ojdbcxxx.jar。

那么我应该如何让我的 2 个 XA 数据源在我的项目中工作呢?谢谢 ...

4

2 回答 2

0

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

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

我从这个线程得到了解决方案:https ://issues.jboss.org/browse/THORN-1270

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

于 2019-07-01T06:13:07.870 回答
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

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

希望它可以帮助一些人,因为我发现医生对此有点差劲。

于 2018-09-30T16:10:56.500 回答