---
schema_version: "1"
id: 027dce3534877b97ea325a4192c8eaf8c9ed75ba38142994da13a8538803de78
title: Manage Transactions in JMS Connector
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/jms-connector/1.10/jms-transactions.md
canonical_url: https://docs.mulesoft.com/jms-connector/1.10/jms-transactions
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f2973b26417b66101a0e759b7970f5a5301de9ee330a3da12bb368ee0c3d600c
description: MuleSoft Documentation Site
release: "1.10"
latest: false
---
---
product: JMS Connector
version: 1.10
keywords: jms, connector, transactions, transactional
---

# Manage Transactions in JMS Connector

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Transactional actions in JMS enable you to execute a series of operations to perform only when the
transaction occurs. Use this feature when you want to:

- Publish a message as part of a transaction  
  When you use the **Publish** operation, the application sends the message to the destination after
  the transaction occurs. If for some reason the transaction fails and a rollback occurs, the
  message is not sent.

- Consume a message as part of a transaction  
  When you use either the **On New Message** source or the **Consume** operation, the message is
  acknowledged only after the transaction occurs. If the transaction rolls back, the message returns
  to the destination for redelivery.

Anypoint Connector for JMS (JMS Connector) provides support for executing the operations by
configuring the **Transactional action** field.

## Configure Transactions for Sources

If you want the **On New Message** source to use a transactional action when sending the messages,
configure the **Transactional action** field to `ALWAYS_BEGIN`. With this configuration, each new
message is processed in a transaction that propagates to all the components in the flow and occurs
after the flow execution completes successfully. The transaction rolls back if the flow execution
returns an error.

By default, other components in the flow do not join the transaction created by the **On New
Message** source. To execute other operations using the source transaction, configure in those
components the **Transactional action** field either with `ALWAYS_JOIN` or `JOIN_IF_POSSIBLE`.

In the following example, you configure the transactional action for new messages:

1.  In Studio, select the **On New Message** source from your flow.

2.  Set the **Destination** field to `${originQueue}`.

3.  In the **Advanced** tab, set the **Transactional action** field to `ALWAYS_BEGIN`.

![In the Advanced tab](/mulesoft/current/en-us/jms-connector/1.10/_images/jms-transaction-1.png)

Figure 1. JMS Connector Transactional action configuration

In the XML editor, the `<jms:listener>` and `transactionalAction` configurations look like this:

```xml
<jms:listener config-ref="JMS_Config" destination="${originQueue}" transactionalAction="ALWAYS_BEGIN"/>
```

## Configure Transactions for Operations

To execute an operation like **Publish** or **Consume** as part of a transaction, configure the
**Transactional action** field to `ALWAYS_JOIN` or `JOIN_IF_POSSIBLE`.

In the following example, you configure the **Publish** and **Consume** operations that join a
transaction initiated by the **On New Message** source:

1.  In the **Mule Palette** view, select **JMS > On New Message**.

2.  Drag **On New Message** onto the Studio canvas.

3.  In the **On New Message** configuration screen, set the **Destination** field to
    `${originQueue}`.

4.  In the **Advanced** tab, set the **Transactional action** field to `ALWAYS_BEGIN`.

5.  Drag a **Publish** operation to the right of the **On New Message** source.

6.  Set the **Destination** field to `#[attributes.properties.userProperties.redirectDestination]`.

7.  In the **Advanced** tab, set the **Transactional action** field to `JOIN_IF_POSSIBLE`.

8.  Drag a **Consume** operation to the right of the **Publish** operation.

9.  Set the **Destination** field to `#[attributes.properties.userProperties.callbackDestination]`.

10. In the **Advanced** tab, set the **Transactional action** field to `JOIN_IF_POSSIBLE`.

![In the Advanced tab](/mulesoft/current/en-us/jms-connector/1.10/_images/jms-transaction-2.png)

Figure 2. JMS Connector Transactional action configuration for Consume operation

In the XML editor, the `transactionalAction` configuration looks like this:

```xml
<flow name="joiningToListenerTransaction">
    <jms:listener config-ref="JMS_Config" destination="${originQueue}" transactionalAction="ALWAYS_BEGIN"/>
    <jms:publish config-ref="JMS_Config" destination="#[attributes.properties.userProperties.redirectDestination]" transactionalAction="JOIN_IF_POSSIBLE"/>
    <jms:consume config-ref="JMS_Config" destination="#[attributes.properties.userProperties.callbackDestination]" transactionalAction="JOIN_IF_POSSIBLE"/>
</flow>
```

In the following example, you configure a scoped transaction, using a Try scope component, the JMS
**Publish** and **Publish consume** operations, and the Validation module **Is true** operation:

1.  In the **Mule Palette** view, select **HTTP > Listener**.

2.  Drag **Listener** onto the Studio canvas.

3.  In the **Listener** configuration screen, set the **Path** field to `/orders`.

4.  Drag a **Try** scope component to the right of the **Listener** source.

5.  Set the **Transactional action** field to `ALWAYS_BEGIN`.

6.  Drag a JMS **Publish** operation into the **Try** scope component.

7.  Set the **Destination** field to `${billingService}` and the **Transactional action** field to
    `ALWAYS_JOIN`.

8.  Drag a JMS **Publish** operation to the right of the first **Publish** operation.

9.  Set the **Destination** field to `${shipmentService}` and the **Transactional action** field to
    `ALWAYS_JOIN`.

10. Drag a **Publish consume** operation to the right of the second **Publish** operation.

11. Set the **Destination** field to `${invoicesVerificationService}`.

12. Drag a Validation module **Is true** operation to the right of the **Publish consume**
    operation.

13. Select **Expression** for the **Expression** menu and set the value to `#[payload]`.

In the XML editor, the `transactionalAction` configuration look like this:

```xml
<flow name="nonTxPublishMustNotJoinCurrentTx">
    <http:listener config-ref="HTTP_Config" path="/orders"/>
    <try transactionalAction="ALWAYS_BEGIN">
        <jms:publish config-ref="config" destination="${billingService}" transactionalAction="ALWAYS_JOIN"/>
        <jms:publish config-ref="config" destination="${shipmentService}" transactionalAction="ALWAYS_JOIN"/>
        <jms:publish-consume config-ref="JMS_Config" destination="${invoicesVerificationService}"/>
        <validation:is-true expression="#[payload]"/>
    </try>
</flow>
```

## See Also

- [JMS Connector Examples](https://docs.mulesoft.com/jms-connector/1.10/jms-examples)

- [JMS Connector Reference](https://docs.mulesoft.com/jms-connector/1.10/jms-connector-reference)
