An XA data source can participate in a transaction that spans multiple resources, such as a database, a message queue, and legacy systems. If a problem occurs, then the XA transaction can roll back any changes made.
The following XML shows a PostgreSQL XA data source:
<datasources>
<datasources>
<xa-datasource jndi-name="java:jboss/PostgresXADS" pool-name="PostgresXADS">
<xa-datasource-property name="ServerName">
localhost
</xa-datasource-property>
<xa-datasource-property name="PortNumber">
5432
</xa-datasource-property>
<xa-datasource-property name="DatabaseName">
postgresdb
</xa-datasource-property>
<driver>postgresql</driver>
<security>
<user-name>admin</user-name>
<password>admin</password>
</security>
<validation>...</validation>
</xa-datasource>
<drivers>
<driver name="postgresql" module="com.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>The hostname for the database server. | |
The port number used to connect to the database server. | |
The database name for the data source. | |
The XA data source class for the JDBC driver provided by the JDBC driver's documentation. |
The following management CLI command creates an XA data source:
[connected /] xa-data-source add \
--name=internal_datasource_name \
-jndi-name=jndi_name --driver-name=driver_name \
--user-name=login --password=password \
--xa-datasource-properties={"ServerName"=>"server",\
"DatabaseName"=>"db_name"}Compared to defining a non-XA datasource, the XA datasource might require properties such as ServerName, PortNumber and DatabaseName.
This depends on the driver in use, but it is required that you provide at least one XA datasource property.
For example, the MariaDB connector version 3, requires only the Url property with the connection string.
The driver for the database can be used for both XA and non-XA data sources
The following CLI command registers the driver with a specified XA data source class:
/subsystem=datasources/jdbc-driver=mysql:add(driver-name=name,driver-module-name=module,driver-xa-datasource-class-name=xa_class)
The following management CLI command adds a MariaDB driver specifying the driver class to use with XA and non-XA transactions:
[connected /] /subsystem=datasources/jdbc-driver=mysql:add\
(driver-name=mysql,\
driver-module-name=com.mysql,\
driver-class=org.mariadb.jdbc.Driver,\
driver-xa-datasource-class-name=org.mariadb.jdbc.MariaDbDataSource)For more information about configuring an XA datasource for different vendors, refer to the Example Datasource Configurations section in the Datasource Management chapter in the Red Hat Red Hat JBoss Enterprise Application Platform 7.4 Configuration Guide documentation at https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/html-single/configuration_guide/index#example_datasource_configurations