Understanding AnyPoint MQ

Vandana K V
Another Integration Blog
7 min readApr 9, 2024

In this blog, let us understand what is AnyPoint MQ, why and how can it be beneficial to Mule Applications.

What Is a Queue & Why Do We Need One?

A queue is a temporary storage area used for inter-app communication — in simple words, to transfer the message from one API/service to another. If we consider an example of API-led connectivity in MuleSoft, we may require a mechanism to send messages from our exp API to the process API so a queue can be used. The exp API will send the message to the queue and the process API will consume the same message from the queue. There maybe a case where you have a huge data in payload that has to be processed one-by-one and storing that might consume more memory. In this case as well, we can push the entire one by one to queue and consume them one-by-one to process the same. These are just simple examples; there are many such use cases where queues can be used.

What Is Anypoint MQ?

Anypoint MQ:

  • Is a cloud messaging service that performs asynchronous messaging scenarios between applications such as queuing and pub/sub.
  • Is managed easily using Anypoint Platform.
  • Supports large payloads, encryption, queuing, and publish/subscribe (pub/sub)paradigms.
  • Enables easy connection to non-Mule applications using the REST API.
  • Provides dead-letter queue (DLQ) for undeliverable messages.
  • Displays usage statistics on the number of messages and API requests.

Note: Anypoint MQ is not included in the trial account. We require a separate Enterprise subscription to use Anypoint MQ.

Anypoint MQ provides its users with the following:

  • Scalable, asynchronous messaging delivered as a fully hosted cloud service. Anypoint MQ provides a fully hosted and managed queues and message exchanges in the cloud. A queue is a temporary storage area. A message exchange binds one or more queues so that a message sent to a message exchange appears in all its bound queues simultaneously.
  • Full integration with Anypoint Platform. Anypoint MQ is built on Anypoint Platform. This means that queues and message exchanges offer the same management capabilities as the platform itself — from environments and business groups for multi-tenant role-based access control to client access management.
  • Connection to Mule and non-Mule apps. Anypoint MQ offers easy connectivity to Mule applications and the REST API allows you to easily interface with non-Mule applications.
  • Access to Anypoint Studio. Anypoint MQ provides Anypoint Studio access, which makes the process of leveraging your queues and message exchanges as simple as drag, drop and configure.
  • Better management. Anypoint MQ displays usage statistics on the number of messages and API requests so you can manage peak usage and subscription parameters.

Anypoint MQ also provides the following technical benefits:

  • Queues and Message Exchanges. Anypoint MQ offers the ability to send messages to queues, pull messages from queues, create a message exchange to perform pub/sub scenarios and send a message to multiple queues.
  • Management console. Anypoint MQ provides users with the ability to monitor queue statistics, purge queues and see how many messages are in flight via the management console.
  • Out-of-the-box connectivity. With the Anypoint MQ connector, users can end and receive messages from any Mule application — whether it’s deployed in CloudHub or used in a hybrid scenario and deployed on-premises.
  • Relevant metrics. Gaining usage information with Anypoint MQ is easy. Organization administrators or owners can view the current and past months usage, the total number of messages and API requests and more. This information is accessed from the Access Management page. For more information, see Anypoint MQ Usage Information.
  • REST API. As mentioned, users can leverage the Anypoint MQ REST APIs — including the Anypoint MQ Administration API, the Anypoint MQ Broker API and Anypoint MQ Statistics API — to easily communicate with non-Mule applications.
  • Environments and role based access control. Anypoint MQ is fully integrated with Anypoint Access Management, allowing you to specify different environments for your queues, who can access each environment and what they can do within each environment.
  • Client management. Create client applications tokens.
  • Large payloads. Anypoint MQ supports payloads up to 10 MB in size.
  • Reliability and disaster recovery. Within each region, MQ services deploy to multiple availability zones (AZs) to provide high availability (HA). If service in one availability zone goes down, the Anypoint MQ service operates normally in that region. If all availability zones go down in a region, then the MQ service is unavailable in that region until at least one of the availability zones comes back up. However, the storage solution for MQ is durable, which means no message is lost for messages that were already in the MQ system before service was interrupted.
  • Secure, encrypted queues. Anypoint MQ data can optionally be encrypted, ensuring that companies can be compliant with their data at rest policies. Anypoint MQ uses PBE with MD5 and DES to encrypt messages.

Creating Queues & Client Apps on Anypoint Platform

First of all, we should have the license to use Anypoint MQ available in the CloudHub platform. Once we have the license, we need to login to the Anypoint Platform where we can see MQ as an option. Click on MQ.

To create a queue, we need to select a region. It is good to select a region that is geographically close, or we can select any region.

Note: We can’t move the queue from one region to another.

In the above image, we can see the region is selected as Asia Pacific (Singapore) and the URL for that is written next to it. This URL is important and it is different for each region and we require it for Anypoint MQ Connector configuration in Anypoint Studio.

If we click the + icon visible in the above image, we can see option to create queue/exchanges.

It will provide you three options to choose from:

  1. Queue: The queue is a storage area where messages are stored for processing.
  2. FIFO (first in, first out): FIFO is also a normal queue where messages are stored. The FIFO queue needs to be used when ordering, whereas in the queue, ordering is not maintained.
  3. Exchange: The exchange is used for broadcasting a messages, like one message to multiple consumers. If any message is send to the exchange, it will be forwarded to all the the queues associated with the exchange.

We can select Queue, Exchange, or FIFO Queue based on requirements.

Let’s create a sample queue:

Once we click Queue, a Create Queue window will popup where we need to fill the details:

Here, TTL means time to live. It defines how long the message is in the queue before Anypoint MQ expires the message and removes it from the queue.

Default Acknowledgement Timeout is how long a message remains unacknowledged before being returned to the queue.

Once we fill the details and click Create Queue, the queue gets created.

We can see the newly created queue with the name test-queue. If you click on the queue, you can see a dashboard on the RHS that shows a graphical view of the messages of the queue and queue details.

Our Queue is successfully is created. To access the queue, we need to create client apps, which will provide us with a unique client ID and password to use this newly created queue.

Click on Client Apps then click on the + icon on the right:

A pop-up will open where we need to give the name of our app and then click Save Changes.

After providing the client app name when we click Save Changes, we will get a client app ID and client secret for this client app as shown in below image.

We can use these details in Anypoint Studio to configure the Anypoint MQ.

Operations

The Anypoint MQ connector provides five operations:

  1. Publish to publish the message to the Queue.
  2. Subscriber to subscribe to the queue and listen for the receiving message.
  3. Consumer to consume a message from the queue.
  4. Ack to send an acknowledgement to the queue about the successful consumption of the message and delete the message from in-flight status.
  5. Nack to send negative acknowledgement to the queue stating the consumed message is not processed successfully; changes the status of the message from in-flight to in-queue to be consumed again by an available consumer.

References:

Anypoint MQ MuleSoft Documentation: https://docs.mulesoft.com/mq/

--

--