Narayana 事务

引入 Maven 依赖

  1. <properties>
  2. <narayana.version>5.9.1.Final</narayana.version>
  3. <jboss-transaction-spi.version>7.6.0.Final</jboss-transaction-spi.version>
  4. <jboss-logging.version>3.2.1.Final</jboss-logging.version>
  5. </properties>
  6. <dependency>
  7. <groupId>org.apache.shardingsphere</groupId>
  8. <artifactId>shardingsphere-jdbc-core</artifactId>
  9. <version>${shardingsphere.version}</version>
  10. </dependency>
  11. <!-- 使用 XA 事务时,需要引入此模块 -->
  12. <dependency>
  13. <groupId>org.apache.shardingsphere</groupId>
  14. <artifactId>shardingsphere-transaction-xa-core</artifactId>
  15. <version>${shardingsphere.version}</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.apache.shardingsphere</groupId>
  19. <artifactId>shardingsphere-transaction-xa-narayana</artifactId>
  20. <version>${shardingsphere.version}</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>org.jboss.narayana.jta</groupId>
  24. <artifactId>jta</artifactId>
  25. <version>${narayana.version}</version>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.jboss.narayana.jts</groupId>
  29. <artifactId>narayana-jts-integration</artifactId>
  30. <version>${narayana.version}</version>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.jboss</groupId>
  34. <artifactId>jboss-transaction-spi</artifactId>
  35. <version>${jboss-transaction-spi.version}</version>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.jboss.logging</groupId>
  39. <artifactId>jboss-logging</artifactId>
  40. <version>${jboss-logging.version}</version>
  41. </dependency>

定制化配置项

可以通过在项目的 classpath 中添加 jbossts-properties.xml 来定制化 Narayana 配置项。

详情请参见Narayana官方文档

设置 XA 事务管理类型

Yaml:

  1. - !TRANSACTION
  2. defaultType: XA
  3. providerType: Narayana

SpringBoot:

  1. spring:
  2. shardingsphere:
  3. props:
  4. xa-transaction-manager-type: Narayana

Spring Namespace:

  1. <shardingsphere:data-source id="xxx" data-source-names="xxx" rule-refs="xxx">
  2. <props>
  3. <prop key="xa-transaction-manager-type">Narayana</prop>
  4. </props>
  5. </shardingsphere:data-source>