Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Anypoint MQ Connector

The Anypoint MQ connector provides publish-subscribe messaging to Mule applications in the cloud or on-premise 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.

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.

Note: You cannot complete the configuration information in this document without an Anypoint MQ license. Contact MuleSoft Sales for a trial license.

Compatibility

Software Version

Mule Runtime

3.7.4 and later

Anypoint Studio

v5 and later

To Install This Connector

  1. In Anypoint Studio, click the Exchange icon in the Studio taskbar.

  2. Click Login in Anypoint Exchange and supply your Anypoint Platform credentials.

  3. In the Exchange window, search for this connector, and click Install.

  4. Follow the prompts to install the connector.

To Update from an Older Version

When an updated version of a connector is released, Anypoint Studio displays the Updates Available popup in the bottom right corner of Studio. Click the popup and install the new version.

To Configure with the Studio Visual Editor

  1. In Studio, click File > New > Mule Project.

  2. Search for "http" and drag the HTTP connector to the Studio Canvas. Click the HTTP connector, and click the green plus sign to the right of Connector Configuration. Click OK to accept the defaults. In the HTTP properties window, set the Path to /mq/{messageId}.

  3. Search for "mq" and drag the Anypoint MQ connector to the canvas. If you cannot find this connector, return to To Install This Connector and ensure you installed the connector.

  4. Click the green plus sign to the right of Connector Configuration.

  5. In the Global Element Properties window:

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

      Possible values are:

      • US East (N. Virginia): https://mq-us-east-1.anypoint.mulesoft.com/api/v1

      • US West (Oregon): https://mq-us-west-2.anypoint.mulesoft.com/api/v1

      • EU (Ireland): https://mq-eu-west-1.anypoint.mulesoft.com/api/v1

      • Asia Pacific (Singapore): https://mq-ap-southeast-1.anypoint.mulesoft.com/api/v1

      • Asia Pacific (Sydney): https://mq-ap-southeast-2.anypoint.mulesoft.com/api/v1

        FIFO queues can reside in US East, US West, and EU Ireland.

    2. In Anypoint Platform, click MQ > Client Apps. If needed, create a client app.

    3. Copy the Anypoint Platform > MQ > Client App > Client App ID value to Studio’s Client ID field.

    4. Copy the Client App > Client Secret value to Studio’s Client Secret field. You can ignore the other settings to test your connector.

    5. Click OK.

  6. Click the Operation field and specify an operation such as Publish or Consume. For information on the Ack and Nack operations, see About Acknowledgement Mode.

  7. If using the Publish or Consume operations, specify the Destination as the name of the queue or message exchange that you set in Anypoint Platform.

  8. For the Publish operation, you can leave the Message ID field empty, or specify a message ID if you want to publish a specific message ID. If a message ID is not set, MQ auto generates a unique message ID for each message that’s sent to a queue. When publishing to FIFO queues, if you specify a Message ID and the Message ID is the same on multiple messages, the messages with the same Message ID are not redelivered.

For a list of all other configuration fields, see the Anypoint MQ Connector Reference.

MQ Schema and Endpoint

If you are creating an XML or standalone application, add this dependency to your pom.xml file:


         
      
1
2
3
4
5
<dependency>
  <groupId>org.mule.tooling.messaging</groupId>
  <artifactId>mule-module-anypoint-mq-ee-studio</artifactId>
  <version>1.2.0</version>
</dependency>

Note: If you are creating an application using Anypoint Studio, when you install the MQ connector, the MQ dependency in the pom.xml file is updated for you.

Additional dependencies for Gradle, EBT, and Ivy are listed in Anypoint Exchange in the Anypoint MQ Connector asset. Click Dependency Snippets for a complete list.

Endpoint:

http://www.mulesoft.org/schema/mule/anypoint-mq

XML and Standalone Configuration

For a list of XML fields, see Anypoint MQ Connector Reference.

Anypoint MQ XML Examples

This section provides these topics:

Example 1: MQ and DataWeave

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


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
        xmlns:anypoint-mq="http://www.mulesoft.org/schema/mule/anypoint-mq" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/anypoint-mq http://www.mulesoft.org/schema/mule/anypoint-mq/current/mule-anypoint-mq.xsd">
  <anypoint-mq:config name="Anypoint_MQ_Configuration" doc:name="Anypoint MQ Configuration">
      <anypoint-mq:provider url="https://mq-us-east-1.anypoint.mulesoft.com/api/v1" clientId="<id>" clientSecret="<secret>"/>
  </anypoint-mq:config>
<flow name="producerFlow">
  <poll doc:name="Poll">
    <dw:transform-message doc:name="Create Customer">
    <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
    "firstName" : "Joe",
    "lastName" : "Schmoe",
    "company" : "Acme, Inc"
}]]></dw:set-payload>
    </dw:transform-message>
  </poll>
        <anypoint-mq:publish config-ref="Anypoint_MQ_Configuration" destination="MyExchange" doc:name="Anypoint MQ">
            <anypoint-mq:message-builder messageId="mq42"/>
        </anypoint-mq:publish>
</flow>
</mule>

Example 2: MQ and Object Store

The following example shows the use of the Anypoint MQ connector to consume information from an object store.


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:anypoint-mq="http://www.mulesoft.org/schema/mule/anypoint-mq"
    xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore"
    xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
    xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
    xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/anypoint-mq http://www.mulesoft.org/schema/mule/anypoint-mq/current/mule-anypoint-mq.xsd">

    <objectstore:config name="ObjectStore_Configuration" partition="employees" doc:name="ObjectStore: Configuration"/>
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <anypoint-mq:config name="Anypoint_MQ_Configuration" doc:name="Anypoint MQ Configuration">
        <anypoint-mq:provider url="https://mq-us-east-1.anypoint.mulesoft.com/api/v1" clientId="<ID>" clientSecret="<SECRET>"/>
    </anypoint-mq:config>
    <flow name="objectstore-store-flow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/store" doc:name="HTTP"/>
        <objectstore:store config-ref="ObjectStore_Configuration" key="#[message.inboundProperties.'http.query.params'.key]" value-ref="#[message.inboundProperties.'http.query.params'.value]" doc:name="ObjectStore"/>
        <anypoint-mq:consume config-ref="Anypoint_MQ_Configuration" destination="MyDemoQueue" doc:name="Anypoint MQ"/>
        <set-payload value= "OK" doc:name="Set Payload"/>
    </flow>
    <flow name="objectstore-retrieve-employee-flow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/retrieve" doc:name="HTTP"/>
        <objectstore:retrieve config-ref="ObjectStore_Configuration" key="#[message.inboundProperties.'http.query.params'.key]" doc:name="Retrieve"/>
        <logger message="Value: #[payload]" level="INFO" doc:name="Log"/>
        <set-payload value="Value : #[payload]" doc:name="Show"/>
    </flow>
</mule>