Contact Free trial Login

Anypoint MQ Connector 2.x - Mule 4

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 documentation set and additional resources listed in See Also.

Prerequisites

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

Software Version

Mule Runtime Engine

4.0.0 and later

Anypoint Studio

7 and later

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.

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:

    <dependency>
      <groupId>com.mulesoft.connectors</groupId>
      <artifactId>anypoint-mq-connector</artifactId>
      <version>${RELEASE}</version>
      <classifier>mule-plugin</classifier>
    </dependency>

To specify a specific version, see the Exchange Anypoint MQ Connector asset. Click Dependency Snippets for a complete list.

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.

  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 FAQ: Anypoint MQ 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:

Operation Description

Publish

Publishes messages to a queue or message exchange.

Consume

Consumes messages from a queue.

Subscribe

Waits for messages from a queue.

ACK

Indicates that the message has been consumed correctly and deletes the message from in-flight status.

NACK

Changes the status of the message from in-flight to in-queue to be consumed again by an available consumer.

  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.

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:

<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>

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.