---
schema_version: "1"
id: c11e0fff4b4d700067bac368d4b2e56e84b79c7decb08026fc471675830cade1
title: Anypoint MQ Connector 2.x
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-mq-connector/2.x/index.md
canonical_url: https://docs.mulesoft.com/anypoint-mq-connector/2.x/
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 30958934c7d78cffe9f2d9390dbba5d46daf77b038434ddb31f5a2df7f00311a
description: MuleSoft Documentation Site
release: 2.x
latest: false
---
---
product: Anypoint MQ Connector
version: 2.x
---

# Anypoint MQ Connector 2.x

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

Support Category: Select

The Anypoint MQ connector provides publish-subscribe messaging to Mule apps using the Anypoint MQ
cloud service.

Anypoint MQ supports a wide range of messaging use cases: enterprise messaging patterns,
asynchronous communications between microservices, IoT, and more. Anypoint MQ also has a REST API
for publishing or consuming messages using any framework such as node.js, Java, Go, and devops bash
scripts.

For more information, see the [Anypoint MQ Overview](https://docs.mulesoft.com/mq/).

## Before You Begin

To use this connector, you should be familiar with Anypoint Studio, Anypoint connectors, and Mule
flows. The Anypoint MQ connector is free, but connecting to the service in Anypoint Platform
requires a license. Free trial software is available.

### Compatibility

<table><colgroup><col> <col></colgroup><thead><tr><th>Software</th><th>Version</th></tr></thead><tbody><tr><td><p>Mule Runtime Engine</p></td><td><p>4.0.0 and later</p></td></tr><tr><td><p>Anypoint Studio</p></td><td><p>7 and later</p></td></tr></tbody></table>

This documentation applies to Anypoint MQ connector 2.x only. To migrate from version 2.x to the
version 3.x, see the [Anypoint MQ 3.x Connector Migration Guide](https://docs.mulesoft.com/anypoint-mq-connector/3.x/anypoint-mq-new-3x-major).

## Install Anypoint MQ Connector

In Anypoint Studio:

1.  Create or open a Mule project.

2.  Click the Exchange **(X)** icon in the Studio task bar.

3.  Enter your Anypoint Platform username and password and click **Sign in**.

4.  Select **All assets** and search for "MQ"

5.  Select "Anypoint MQ Connector — Mule 4", and click **Add to project**.

6.  Follow the prompts to install the connector.

For standalone apps or apps written in XML:

1.  Open your Mule project in Anypoint Studio.

2.  Add the connector as a dependency in the pom.xml file:

    ```xml
    <dependency>
      <groupId>com.mulesoft.connectors</groupId>
      <artifactId>anypoint-mq-connector</artifactId>
      <version>x.x.x</version>
      <classifier>mule-plugin</classifier>
    </dependency>
    ```

Replace `x.x.x` with the version that corresponds to the connector you are using.

To obtain the most up-to-date `pom.xml` file information, access the connector in
[Anypoint Exchange](https://www.mulesoft.com/exchange/) and click **Dependency Snippets**.

## Configure Anypoint MQ in a Mule Project

In Anypoint Studio:

1.  Install the connector, if it’s not already installed. See
    [Install Anypoint MQ Connector](#install-anypoint-mq-connector).

2.  Create or open a Mule project.

3.  Search for "mq" in the **Mule Palette** to see all the available operations for the **Anypoint
    MQ** connector.

### Create a New Configuration for the Anypoint MQ Connector

1.  Drag the operation from the palette to the canvas, then select it.

2.  Click the green plus sign to the right of **Connector configuration**.

3.  Specify the broker URL for the region you want your MQ queues and exchanges to reside.

    To obtain and configure this URL, in Anypoint Platform, select **MQ > Destinations**. See
    [Anypoint MQ Regions](https://docs.mulesoft.com/mq/mq-faq#regions) for the list of regions.

4.  In Anypoint Platform, click **MQ > Client Apps**.

    If needed, create a client app.

5.  Copy the **Client App ID** value to the **Client App ID** field in Studio.

6.  Copy the **Client Secret** value to the **Client Secret** field in Studio.

    You can ignore the other settings to test your connector.

7.  Click **Test Connection** to verify the Anypoint MQ Default subscriber.

8.  Click **OK**.

### Select an Operation

In the **Mule Palette** in Studio, click **Anypoint MQ** to display a list of available operations:

<table><colgroup><col> <col></colgroup><thead><tr><th>Operation</th><th>Description</th></tr></thead><tbody><tr><td><p><a href="https://docs.mulesoft.com/anypoint-mq-connector/2.x/anypoint-mq-publish">Publish</a></p></td><td><p>Publishes messages to a queue or message exchange.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/anypoint-mq-connector/2.x/anypoint-mq-consume">Consume</a></p></td><td><p>Consumes messages from a queue.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/anypoint-mq-connector/2.x/anypoint-mq-listener">Subscribe</a></p></td><td><p>Waits for messages from a queue.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/anypoint-mq-connector/2.x/anypoint-mq-ack">ACK</a></p></td><td><p>Indicates that the message has been consumed correctly and deletes the message from in-flight status.</p></td></tr><tr><td><p><a href="https://docs.mulesoft.com/anypoint-mq-connector/2.x/anypoint-mq-ack">NACK</a></p></td><td><p>Changes the status of the message from in-flight to in-queue to be consumed again by an available consumer.</p></td></tr></tbody></table>

1.  Drag the operation from the palette to the canvas, then select it.

2.  Configure the operation accordingly.

    For a list of configuration fields for each operation and information about XML elements, see
    the [Anypoint MQ Connector Reference - 2.x](https://docs.mulesoft.com/anypoint-mq-connector/2.x/anypoint-mq-connector-reference).

## Example: Anypoint MQ Bridge with DataWeave

The following example illustrates the use of the Anypoint MQ connector with DataWeave to transform a
message to JSON:

```xml
<anypoint-mq:default-subscriber-config name="MQ_Configuration">
    <anypoint-mq:connection url="https://mq-us-east-1.anypoint.mulesoft.com/api/v1"
    clientId="${env.clientId}" clientSecret="${env.clientSecrete}"/>
</anypoint-mq:default-subscriber-config>

<flow name="producerFlow">
  <anypoint-mq:subscriber config="MQ_Configuration" destination="${inbound}"/>

  <http:request config-ref="Invoice_API" method="POST" path="/invoicesProcessing" >
    <http:body>#[output application/json ---
    {
        body : payload,
        origin : attributes.message.properties.orgId,
        trackingNumber : attributes.message.id
    }]</http:body>
  </http:request>
</flow>
```

## See Also

- [Anypoint MQ Overview](https://docs.mulesoft.com/mq/)

- [FAQ: Anypoint MQ](https://docs.mulesoft.com/mq/mq-faq)

- [Anypoint MQ REST APIs](https://docs.mulesoft.com/mq/mq-apis)

- [Anypoint MQ Connector on Exchange](https://anypoint.mulesoft.com/exchange/com.mulesoft.connectors/anypoint-mq-connector/)
