6.11.3.4 Configure JAX-RS App with a Non-XA and Non-JDBC Resource

Use the information provided in this section to configure your JAX-RS participant applications when you use a resource that does not support XA and JDBC.

Your application can connect to multiple XA-compliant resource managers. However, only a single non-XA resource can participate in a transaction.
  1. Before you begin, ensure that you have configured the property values for the MicroTx library. See Configure Library Properties.
    Ensure that oracle.tmm.xa.XaSupport is set to false and oracle.tmm.xa.LLRSupport or oracle.tmm.xa.LRCSupport is set to true.
    • To enable the Logging Last Resource (LLR) optimization, set the following values for the environment variables.
      oracle.tmm.xa.XaSupport = false
      oracle.tmm.xa.LLRSupport = true
      oracle.tmm.xa.LRCSupport = false
    • To enable the Last Resource Commit (LRC) optimization, set the following values for the environment variables.
      oracle.tmm.xa.XaSupport = false
      oracle.tmm.xa.LLRSupport = false
      oracle.tmm.xa.LRCSupport = true
  2. Include the MicroTx Java library file as a maven dependency in the application's pom.xml file. The following sample code is for the 24.2 release. Provide the correct version, based on the release version that you want to use.
    • In Jakarta EE8 environments, such as Helidon 2.x, use the TmmLib file.

      <dependency>
           <groupId>com.oracle.tmm.jta</groupId>
           <artifactId>TmmLib</artifactId>
           <version>24.2</version>
      </dependency>
    • In Jakarta EE9 environments, such as Helidon 3.x applications, use the TmmLib-jakarta file.

      <dependency>
           <groupId>com.oracle.tmm.jta</groupId>
           <artifactId>TmmLib-jakarta</artifactId>
           <version>24.2</version>
      </dependency>
  3. Enable session affinity. See Enable Session Affinity.
  4. Implement the NonXAResource interface.
    public class MongoDbNonXAResource implements NonXAResource {
    // Provide application-specific code for all the methods in the NonXAResource interface.
    }

    For information about the NonXAResource interface, see Transaction Manager for Microservices Java API Reference.

    If you have enabled the LRC optimization, you don't have to implement the recover() method in the NonXAResource interface as the commit() method returns NULL for commitRecord in LRC.

  5. After implementing the NonXAResource interface, import the MicroTx library files, and then produce a non-XA resource. Annotate the non-XA resource that you create with @NonXa annotation. The MicroTx library consumes the object that you annotate.

    The following example shows a sample implementation for a MongoDB resource. Create code for your application based on your business requirements. In this example, the NonXaResourceFactory class supplies the NonXAResource. It produces a non-XA resource, and then the MicroTx library consumes the non-XA resource.

    package com.oracle.mtm.sample.nonxa;
    
    import oracle.tmm.jta.nonxa.NonXAResource;
    import oracle.tmm.jta.nonxa.NonXa;
    
    import javax.enterprise.inject.Produces;
    import javax.inject.Inject;
    import javax.ws.rs.ext.Provider;
    import java.util.function.Supplier;
    
    @Provider
    public class NonXaResourceFactory implements Supplier<NonXAResource> {
    
        @Inject
        MongoDbNonXAResource nonXAResource;
    
        @Produces    
        @NonXa
        public NonXAResource getNonXAResource() {
            return nonXAResource;
        }
    
      @Override
        public NonXAResource get() {
            return getNonXAResource();
        }
    }
  6. Save the changes.

Source code of a sample JAX-RS transaction participant application which uses the MicroTx library and XA transaction protocol is available in the department-nonxa folder which is located in the microtx-samples GitHub repository. You can use this as a reference while integrating the MicroTx libraries with your application.