Configure Message Acknowledgement with the JMS Connector

Anypoint Connector for JMS (JMS Connector) provides different message acknowledgement modes to configure for the Ack, Consume, On New Message, and Recovery session operations:

  • Automatic acknowledgement on success

  • Immediate acknowledgement

  • Manual acknowledgement

The following examples illustrate how to configure each message acknowledgement mode.

Configure Automatic Acknowledgement on Success Mode

Configure the automatic acknowledgement on success mode in the On New Message source by setting the Acknowledge Mode field to either one of these modes:

  • AUTO
    Automatically acknowledges (ACK) the received message only if the flow execution completes successfully; otherwise, the message is not acknowledged and is redelivered.

  • DUPS_OK
    Like AUTO mode, automatically acknowledges (ACK) the received message only if the flow execution completes successfully, but leads to duplicate messages if the message is redelivered before the ACK is performed.

In the following example, you configure the AUTO acknowledgement mode:

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

  2. In the On New Message configuration screen, in Destination, specify the name of the destination from which to consume the message, for example, #[vars.destination].

  3. From the Acknowledge Mode menu, select AUTO.

In the On New Message source screen
Figure 1. JMS Connector Auto Acknowledgement Mode configuration

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

<jms:listener  config-ref="JMS_Config" destination="#[vars.destination]" ackMode="AUTO"/>

Configure Immediate Acknowledgement Mode

Configure the immediate acknowledgement mode in the On New Message source by using the Acknowledge Mode field, or in the Consume operation by using the Ack mode field. Set the fields to IMMEDIATE. This mode automatically acknowledges (ACK) the message after it is consumed and before to any application processing of the message.
The result of automatically acknowledging the message is that the message won’t be redelivered if any error occurs during message processing, requiring application logic like a "dead letter" queue to manage errors without losing messages.

In the following example, you configure the IMMEDIATE acknowledgement mode for the Consume operation:

  1. In Studio, select the Consume operation from your flow.

  2. In the Consume configuration screen, in Destination, specify the name of the destination from which to consume the message, for example, #[vars.destination].

  3. From the Ack mode menu, select IMMEDIATE.

In the Consume operation screen
Figure 2. JMS Connector Immediate Acknowledgement Mode configuration

In the XML editor, the <jms:consume> and ackMode configurations look like this:

Configure Manual Acknowledgement Mode

Configure the manual acknowledgement mode in the On New Message source by using the Acknowledge Mode field, or in the Consume operation by using the Ack mode field. Set these fields to MANUAL. This mode delegates all responsibility for performing message acknowledgement (ACK) to the application logic.

Every message received by either the On New Message or Consume operations includes an acknowledgement ID in the Mule message attributes, that identifies the message uniquely for a given connection.
The acknowledgement ID that identifies the message is then passed to the Ack operation in the Ack id field.

In the following example, you configure the MANUAL acknowledgement mode for the Consume operation:

  1. In Studio, select the Consume operation from your flow.

  2. In the Consume configuration screen, in Destination, specify the name of the destination from which to consume the message, for example, openTickets.

  3. From the Ack mode menu, select MANUAL.

  4. Drag a Logger component to the right of the Consume operation.

  5. Set the Message field to #[payload].

  6. Drag an Ack operation to the right of the Logger component.

  7. Set the Ack id field to the acknowledgement ID of the message session to recover, for example, #[attributes.ackId].

In the Ack operation screen
Figure 3. JMS Connector Ack operation configuration

In the XML editor, the <jms:consume>, ackMode, and ackId configurations look like this:

<flow name="consumerWithManualAck">
    <jms:consume config-ref="JMS_config" destination="openTickets" ackMode="MANUAL"/>

    <!--Do message processing-->
    <logger message="#[payload]">

    <jms:ack ackId="#[attributes.ackId]"/>
</flow>

Configure Manual Session Recovery

With manual acknowledgement mode, all messages received but not acknowledged are not redelivered by the broker. If there is an error during the message processing, you must manually recover all the messages in the session that have to be redelivered by using the Recover session operation. The connection used to recover the session has to be the the same as the connection for receiving the message.

In the following example, you configure the MANUAL acknowledgement mode and how to recover the session:

  1. In Studio, select the Consume operation from your flow.

  2. In the Consume configuration screen, in Destination, specify the name of the destination from which to consume the message, for example, ${destination}.

  3. Set the Ack mode field to MANUAL.

  4. Drag a Logger component to the right of the Consume operation.

  5. Set the Message field to #[payload].

  6. Drag an Ack operation to the right of the Logger component.

  7. Set the Ack id field to the acknowledgement ID of the message session to recover, for example, #[vars.consumedMessage.attributes.ackId].

  8. In your flow, expand the Error handling section by clicking the small arrow.

  9. Drag an On Error Propagate component in the Error handling section.

  10. Drag a Recover session operation inside the On Error Propagate component.

  11. Set the Ack id field to #[vars.consumedMessage.attributes.ackId].

In the Recover session operation screen
Figure 4. JMS Connector Recover session operation configuration

In the XML editor, the <jms:consume>, ackMode, and ackId configurations look like this:

<flow name="consumerWithManualAck">
    <jms:consume config-ref="JMS_config" destination="${destination}"
                 ackMode="MANUAL" target="consumedMessage" targetValue="#[message]"/>

    <!--Do message processing-->
    <logger message="#[payload]">

    <jms:ack ackId="#[vars.consumedMessage.attributes.ackId]"/>

    <error-handler>
        <on-error-propagate>
            <!--In case of error, recover the session-->
            <jms:recover-session ackId="#[vars.consumedMessage.attributes.ackId]"/>
        </on-error-continue>
    </error-handler>
</flow>