---
schema_version: "1"
id: c8f4b8a79401d7af2afb30c4cf4e8b4e5fc01f65e52e7206447f05589cd951e0
title: Anypoint MQ ACK and NACK Operations
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-mq-connector/2.x/anypoint-mq-ack.md
canonical_url: https://docs.mulesoft.com/anypoint-mq-connector/2.x/anypoint-mq-ack
source_site: docs.mulesoft.com
content_type: documentation
content_hash: c9560e04943e450697202110968f5d1cc83a7dcf31d95fda7c4a890412f5bf14
description: MuleSoft Documentation Site
release: 2.x
latest: false
---
---
product: Anypoint MQ Connector
version: 2.x
---

# Anypoint MQ ACK and NACK Operations

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

Acknowledging a message (ACK) informs the broker that the message has been processed and must be
removed from the queue to prevent redelivery. Not acknowledging a message (NACK) tells the broker to
not process the message and to return the message to the queue for redelivery to any available
consumer.

The Anypoint MQ connector provides three acknowledgment configurations: Immediate, Automatic, and
Manual.

## Immediate Acknowledgment

Use the `IMMEDIATE` acknowledgment mode to acknowledge messages as your app consumes them and before
processing them.

When Anypoint MQ acknowledges a message, it removes the message from the queue and doesn’t redeliver
it if an error occurs during processing.

If the app restarts between being acknowledged and dispatched, the message might not be available
again because it was deleted from the queue. To prevent message deletion until after processing, use
the `AUTO` or `MANUAL` acknowledgment mode instead.

If an error occurs during message processing using `IMMEDIATE` mode, Anypoint MQ throws an
`ANYPOINT-MQ:ACKING` error. To manage errors without losing messages, use a dead letter queue.

## Automatic Acknowledgment

Use the `AUTO` acknowledgment mode to acknowledge a received message automatically only if the flow
execution finishes successfully.

If an error occurs during flow execution, execution terminates, and the message is returned to the
queue for redelivery.

## Manual Acknowledgment

Use the `MANUAL` acknowledgment mode to delegate all responsibility to the app logic to decide when
to acknowledge the message.

With this configuration, every message received has an `AnypointMQMessageContext` object in the Mule
message `attributes` that identifies this message uniquely for a given connection.

### Acknowledgment Timeout

When using either `AUTO` or `MANUAL` acknowledgment modes, you can use the `acknowledgementTimeout`
parameter to control how long the message remains in-flight waiting to be acknowledged, before
automatically returning to the queue.

The app must execute either an ACK or NACK operation on the message before the timeout expires.

When using `acknowledgementTimeout`, consider expected app-time processing, including time for
unexpected delays, such as external systems delay and app back-pressure due to high load. For
example, if you expect the consumed message to be processed in 10 seconds, set the
`acknowledgementTimeout` to a minimum of 15 seconds.

### Execute an ACK Operation

Acknowledging a message informs the broker that the message has been processed and must be removed
from the queue to prevent redelivery.

The\`AnypointMQMessageContext\` object identifies the message to pass on to the `anypoint-mq:ack`
operation:

```xml
<flow name="consumerWithManualAck">
    <anypoint-mq:consume
       destination="${destination}"
       acknowledgementMode="MANUAL"
       config-ref="AMQ_Config"/>

    <!-- Process messages without modifying the payload-->
    <jms:publish config="JMS_config" destination="${bridgedDestination}">

    <anypoint-mq:ack messageContext="#[attributes]" config-ref="AMQ_Config"/>
</flow>
```

If a non-void operation is invoked during message processing, the payload and attributes of the Mule
message are modified. To perform an ACK operation after processing, you must save the original
attributes in a variable.

To save attributes to use later, use the `target` and `targetValue` parameters to store the whole
message in a variable:

```xml
<flow name="consumerWithManualAck">
    <anypoint-mq:consume destination="${destination}"
                 acknowledgementMode="MANUAL"
                 config-ref="AMQ_Config"
                 target="mqMessage"
                 targetValue="#[message]"/>

    <!--Do message processing changing the payload-->
    <http:request method="POST" path="/invoicesProcessing" config-ref="httpRequestConfig">
            <http:body>#[vars.mqMessage.payload]</http:body>
    </http:request>

    <anypoint-mq:ack messageContext="#[vars.mqMessage.attributes]" config-ref="AMQ_Config"/>
</flow>
```

### Execute a NACK Operation

Not acknowledging a message informs the broker that the message was not processed successfully and
commands the broker to return the message to the queue for redelivery to any available consumer.

The `AnypointMQMessageContext` object that identifies the message is passed to the
`anypoint-mq:nack` operation:

```xml
<flow name="consumerWithManualAck">
    <anypoint-mq:consume
                 destination="${destination}"
                 acknowledgementMode="MANUAL"
                 config-ref="AMQ_Config"/>

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

    <anypoint-mq:nack messageContext="#[attributes]" config-ref="AMQ_Config"/>
</flow>
```

## See Also

- [Anypoint MQ Consume Operation](https://docs.mulesoft.com/anypoint-mq-connector/2.x/anypoint-mq-consume)

- [Anypoint MQ Subscriber Source](https://docs.mulesoft.com/anypoint-mq-connector/2.x/anypoint-mq-listener)
