<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>anypoint-mq-connector</artifactId>
<version>x.x.x</version>
<classifier>mule-plugin</classifier>
</dependency>
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 Overview.
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
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:
-
Create or open a Mule project.
-
Click the Exchange (X) icon in the Studio task bar.
-
Enter your Anypoint Platform username and password and click Sign in.
-
Select All assets and search for "MQ"
-
Select "Anypoint MQ Connector — Mule 4", and click Add to project.
-
Follow the prompts to install the connector.
For standalone apps or apps written in XML:
-
Open your Mule project in Anypoint Studio.
-
Add the connector as a dependency in the pom.xml file:
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 and click Dependency Snippets.
Configure Anypoint MQ in a Mule Project
In Anypoint Studio:
-
Install the connector, if it’s not already installed. See Install Anypoint MQ Connector.
-
Create or open a Mule project.
-
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
-
Drag the operation from the palette to the canvas, then select it.
-
Click the green plus sign to the right of Connector configuration.
-
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 for the list of regions.
-
In Anypoint Platform, click MQ > Client Apps.
If needed, create a client app.
-
Copy the Client App ID value to the Client App ID field in Studio.
-
Copy the Client Secret value to the Client Secret field in Studio.
You can ignore the other settings to test your connector.
-
Click Test Connection to verify the Anypoint MQ Default subscriber.
-
Click OK.
Select an Operation
In the Mule Palette in Studio, click Anypoint MQ to display a list of available operations:
Operation | Description |
---|---|
Publishes messages to a queue or message exchange. |
|
Consumes messages from a queue. |
|
Waits for messages from a queue. |
|
Indicates that the message has been consumed correctly and deletes the message from in-flight status. |
|
Changes the status of the message from in-flight to in-queue to be consumed again by an available consumer. |
-
Drag the operation from the palette to the canvas, then select it.
-
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>