Este contenido no está disponible en el idioma seleccionado.

14.4. Configuring JMS Transactions


Overview

CXF 3.0 supports both local JMS transactions and JTA transactions on CXF endpoints, when using one-way messaging.

Local transactions

Transactions using local resources roll back the JMS message only when an exception occurs. They do not directly coordinate other resources, such as database transactions.
To set up a local transaction, configure the endpoint as you normally would, and set the property sessionTrasnsacted to true.
Note
For more information on transactions and pooling, see the Red Hat JBoss Fuse Transaction Guide.

JTA transactions

Using JTA transactions, you can coordinate any number of XA resources. If a CXF endpoint is configured for JTA transactions, it starts a transaction before calling the service implementation. The transaction will be committed if no exception occurs. Otherwise, it will be rolled back.
In JTA transactions, a JMS message is consumed and the data written to a database. When an exception occurs, both resources are rolled back, so either the message is consumed and the data is written to the database, or the message is rolled back and the data is not written to the database.
Configuring JTA transactions requires two steps:
  1. Defining a transaction manager
    • bean method
      • Define a transaction manager
        <bean id="transactionManager" 
           class="org.apache.geronimo.transaction.manager.GeronimoTransactionManager"/>
        Copy to Clipboard Toggle word wrap
      • Set the name of the transaction manager in the JMS URI
        jms:queue:myqueue?jndiTransactionManager=TransactionManager
        Copy to Clipboard Toggle word wrap
        This example finds a bean with the ID TransactionManager.
    • OSGi reference method
      • Look up the transaction manager as an OSGi service using Blueprint
        <reference id="TransactionManager" interface="javax.transaction.TransactionManager"/>
        Copy to Clipboard Toggle word wrap
      • Set the name of the transaction manager in the JMS URI
        jms:jndi:myqueue?jndiTransactionManager=java:comp/env/TransactionManager
        Copy to Clipboard Toggle word wrap
        This example looks up the transaction manager in JNDI.
  2. Configuring a JCA pooled connection factory
    Using Spring to define the JCA pooled connection factory:
    <bean id="xacf" class="org.apache.activemq.ActiveMQXAConnectionFactory">
      <property name="brokerURL" value="tcp://localhost:61616" />
    </bean>
    
    <bean id="ConnectionFactory" class="org.apache.activemq.jms.pool.JcaPooledConnectionFactory">
      <property name="transactionManager" ref="transactionManager" />
      <property name="connectionFactory" ref="xacf" />
    </bean>
    Copy to Clipboard Toggle word wrap
    In this example, the first bean defines an ActiveMQ XA connection factory, which is given to a JcaPooledConnectionFactory. The JcaPooledConnectionFactory is then provided as the default bean with id ConnectionFactory.
    Note that the JcaPooledConnectionFactory looks like a normal ConnectionFactory. But when a new connection and session are opened, it checks for an XA transaction and, if found, automatically registers the JMS session as an XA resource. This allows the JMS session to participate in the JMS transaction.
    Important
    Directly setting an XA ConnectionFactory on the JMS transport will not work!
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat