Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 6. XA Transactions in Red Hat JBoss Fuse
Abstract
Red Hat JBoss Fuse provides a built-in global XA transaction manager, which applications can access if they need to coordinate transactions across multiple resources.
6.1. Transaction Architecture
Overview
Figure 6.1, “OSGi Transaction Architecture” shows an overview of the OSGi transaction architecture in Red Hat JBoss Fuse. The core of the architecture is a JTA transaction manager based on Apache Geronimo, which exposes various transaction interfaces as OSGi services.
Figure 6.1. OSGi Transaction Architecture
OSGi mandated transaction architecture
The JTA Transaction Services Specification section of the OSGi Service Platform Enterprise Specification describes the kind of transaction support that can (optionally) be provided by an OSGi container. Essentially, OSGi mandates that the transaction service is accessed through the Java Transaction API (JTA).
The transaction service exports the following JTA interfaces as OSGi services (the JTA services):
javax.transaction.UserTransaction
javax.transaction.TransactionManager
javax.transaction.TransactionSynchronizationRegistry
Only one JTA provider should be made available in an OSGi container. In other words, the JTA services are registered only once and the objects obtained by importing references to the JTA services must be unique.
Spring transaction integration
The JBoss Fuse transaction service exports the following Spring interface as an OSGi service:
org.springframework.transaction.PlatformTransactionManager
By obtaining a reference to the
PlatformTransactionManager
OSGi service, it is possible to integrate application bundles written using the Spring transaction API into the JBoss Fuse transaction architecture.
Red Hat JBoss Fuse transaction implementation
JBoss Fuse provides an OSGi-compliant implementation of the transaction service through the Apache Aries
transaction
feature, which consists mainly of the following bundles:
org.apache.aries.transaction.manager org.apache.aries.transaction.wrappers org.apache.aries.transaction.blueprint
The Aries transaction feature exports a variety of transaction interfaces as OSGi services (making them available to other bundles in the container), as follows:
- JTA interfaces—the JTA
UserTransaction
,TransactionManager
, andTransactionSynchronizationRegistry
interfaces are exported, as required by the OSGi transaction specification. - Spring transaction interface—the Spring
PlatformTransactionManager
interface is exported, in order to facilitate bundles that are written using the Spring transaction APIs.
The
PlatformTransactionManager
OSGi service and the JTA services access the same underlying transaction manager.
Installing the transaction feature
To access the JBoss Fuse transaction implementation, you must install the transaction feature. In a standalone container, enter the following console command:
JBossFuse:karaf@root> features:install transaction
If you are deploying into a fabric, add the
transaction
feature to your application's profile.
Geronimo transaction manager
The underlying implementation of the JBoss Fuse transaction service is provided by the Apache Geronimo transaction manager. Apache Geronimo is a full implementation of a J2EE server and, as part of the J2EE implementation, Geronimo has developed a sophisticated transaction manager with the following features:
- Support for enlisting multiple XA resources.
- Support for 1-phase and 2-phase commit protocols.
- Support for suspending and resuming transactions.
- Support for automatic transaction recovery upon startup.
The transaction recovery feature depends on a transaction log, which records the status of all pending transactions in persistent storage.
Accessing Geronimo directly
Normally, the Geronimo transaction manager is accessed indirectly—for example, through the JTA wrapper layer or through the Spring wrapper layer. But if you need to access Geronimo directly, the following interface is also exposed as an OSGi service:
org.apache.geronimo.transaction.manager.RecoverableTransactionManager
HOWL transaction log
The implementation of the transaction log is provided by HOWL, which is a high speed persistent logger that is optimized for XA transaction logs.
JTA-based application bundles
Normally, it is recommended that application bundles access the transaction service through the JTA interface. To use the transaction service in a JTA-based application bundle, import the relevant JTA service as an OSGi service and use the JTA service to begin, commit, or rollback transactions.
Spring-based application bundles
If you have already implemented an application bundle using the Spring transaction API, you might find it more convenient to access the transaction service through the Spring API (represented by the
PlatformTransactionManager
Java interface). This means that you are able to deploy the same source code either in a pure Spring container or in an OSGi container, by changing only the configuration snippet that obtains a reference to the transaction service.
References
The following specifications are relevant to the transaction architecture in JBoss Fuse:
- OSGi transaction specification—in section 123 JTA Transaction Services Specification v1.0 from the OSGi Service Platform Enterprise Specification v4.2
- Spring transactions API—see the Transaction Management chapter from the current Spring Reference Manual.