Chapter 8. Camel Quarkus transaction guide
8.1. About the transaction guide Copy linkLink copied to clipboard!
This guide provides information and instructions for implementing transactional applications with Red Hat build of Apache Camel for Quarkus.
8.2. JTA dependencies Copy linkLink copied to clipboard!
In order to use camel-quarkus-jta, you need to include the following dependency in your pom.xml
<dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jta</artifactId> </dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jta</artifactId>
</dependency>
This leverages quarkus-narayana-jta to provide JTA support in Camel.
8.2.1. Important configurations Copy linkLink copied to clipboard!
There are some important quarkus.transaction-manager configurations you need to be aware of:
| Configuration | Default value | Description | Comment |
|---|---|---|---|
|
|
| Identifes the node. It needs to be unique and stable over both transaction manager and container restarts. | For more information, see Configuring transaction node name identifier in the Quarkus documentation. |
|
|
|
Configures where the transaction logs are stored - either in a directory ( | For a cloud environment without access to persistent volumes, consider using the jdbc object store. For more information, see Configure storing of Quarkus transaction logs in a database section in the Quarkus documentation |
|
|
| Enables recovery of pending transactions in case of a JVM crash or shutdown. |
We recommend that you set it to |
8.3. Configuring transactional resources Copy linkLink copied to clipboard!
8.3.1. JDBC Datasource configuration Copy linkLink copied to clipboard!
To configure the datasource:
- Include the relevant jdbc extension by following the Configure datasources in Quarkus section in the Quarkus datasource guide.
The extensions are integrated with the Quarkus agroal extension to support pooling and XA transactions.
Optional
If you want to use the datasource in a XA transaction, you must enable it:
quarkus.datasource.jdbc.transactions = xaquarkus.datasource.<datasource-name>.jdbc.transactions = xaFor more information, refer to the Narayana transaction manager integration section in the Quarkus datasource guide.
Do not mix using non-XA and XA datasource in a transaction.
It is not a transaction safe.
8.3.2. JMS Configuration Copy linkLink copied to clipboard!
In order to use JMS with distributed transactions, you must do the following:
Use
quarkus-pooled-jmsto support pooling and transaction, by including the following dependency in yourpom.xml:<dependency> <groupId>io.quarkiverse.messaginghub</groupId> <artifactId>quarkus-pooled-jms</artifactId> </dependency><dependency> <groupId>io.quarkiverse.messaginghub</groupId> <artifactId>quarkus-pooled-jms</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enable XA support by setting
.transactiontoxa:quarkus.pooled-jms.transaction = xa
For more details, see Support for connection pooling and X/Open XA distributed transactions in the JMS extension documentation.
8.4. Examples Copy linkLink copied to clipboard!
- JPA and JMS
We use Narayana as the standalone JTA Transaction Manager implementation, and Hibernate as the JPA Adapter.
- Message Bridge
A basic REST endpoint is provided for users to dispatch a message to the IBM MQ queue. Messages from the IBM MQ are relayed to an ActiveMQ queue within an XA transaction. This example showcases the transaction functionality with rollback and recovery.
8.5. Transaction policies Copy linkLink copied to clipboard!
There are six transaction policies:
| Policy | Description | Comment |
|---|---|---|
|
| Support a current transaction; throw an exception if no current transaction exists. | |
|
| Do not support a current transaction; throw an exception if a current transaction exists. | |
|
| Do not support a current transaction; rather always execute non-transactionally. | |
|
| Support a current transaction; create a new one if none exists. | Default |
|
| Create a new transaction, suspending the current transaction if one exists. | |
|
| Support a current transaction; execute non-transactionally if none exists. |
For more details, see Using different transaction propagations in the Quarkus Transactional client documentation.
8.6. Known issues Copy linkLink copied to clipboard!
8.6.1. Non-XA datasource compatibility Copy linkLink copied to clipboard!
Since 3.8.4, there is a compatibility break issue when using non-XA datasource. For more information see the pull request 40365