
Anypoint MQ Consume Operation - Mule 4
The consume
operation in the Anypoint MQ connector enables the app consume a single message at any time of the flow, from any destination, using the acknowledgment strategy that supports your use case.
Incoming Message Structure
Every incoming message consists of two parts:
-
payload
- Represents the message body -
attributes
- Contains metadata for the received message, such as its ID or other properties

Message Consumption
The simplest way to consume a message from a queue is to drag the Consume operation from the Mule palette to the canvas and configure the Queue
parameter with the name of the queue from which to retrieve the message:

<anypoint-mq:consume config-ref="Anypoint_MQ_config" destination="myQueue"/>
The Consume operation in this example consumes the first available message in myQueue
and converts it to a MuleMessage
instance with this structure:
-
The message body as payload.
-
The message metadata in the message attributes. Attributes might include
messageId
orredeliveryCount
.
Use a DataWeave expression in the Queue
parameter to dynamically change the target queue from which to consume the message.
Consumed Message Acknowledgment
-
Automatic
By default,
acknowledgementMode
isIMMEDIATE
, meaning that the message is acknowledged as soon as it is consumed from the queue and before it’s delivered to the Mule flow. If the message acknowledgment fails, the Consume operation terminates with anANYPOINT-MQ:ACKING
error.For more information, see Immediate Acknowledgment.
-
Manual
To manually control the acknowledgment of the message, change
acknowledgementMode
toMANUAL
. When using theMANUAL
acknowledgment mode, the app logic decides when to perform the acknowledgment of the message, using the ACK or NACK operations.To perform the manual acknowledgment, you need the value of
ackToken
provided as part of the resulting message attributes.For more information, see Manual Acknowledgment.
For information about acknowledgment timeouts, see Acknowledgment Timeout.
Empty Queue Management
When a queue has messages, the Consume operation returns immediately with one of the messages. When a queue is empty, the operation behavior depends on how you set the 'pollingTime' parameter:
-
0
If you set the
pollingTime
parameter to0
, the Consume operation returns immediately without any error and produces anull
message as the result when the queue is empty. -
1
to20
If you set the
pollingTime
parameter to a value ranging from 1 to 20 seconds the Consume operation waits for a new message to arrive for the time specified bypollingTime
. If no message is received within the given time window, this operation fails with anANYPOINT-MQ:TIMEOUT
error.
By default, the Consume operation waits for 10 seconds for a new message to arrive when consuming from an empty queue. Consume fails if no message arrives in that timeframe.
Output Message Metadata
Each message received consists of two parts: Payload
and Attributes
. Attributes
contains the metadata for the message.
This metadata maps all the information available in an Anypoint MQ message, including:
-
Message ID
-
Headers Map
-
Properties Map

For information about the attributes
structure, see the Consume operation in the Anypoint MQ Connector Reference - 3.x.