Anypoint MQ- On Anypoint Platform

Apisero
5 min readAug 26, 2021

--

Author: Kishori Patil

Content:

  • The Anypoint MQ provides publish-subscribe messaging to Mule apps using the Anypoint MQ cloud service.
  • You can use this to send data between two applications or with multiple applications.
  • MQ can be used as Queue or DLQ.
  • The queue will temporarily store the messages sent to it, and those messages can be consumed by one or more applications.
  • When MQ messages are routed to a destination and not processed successfully, they will be sent to DLQ.
  • DLQ will also temporarily store the messages, but they are sent to DLQ only when messages are not processed successfully.
  • Let’s see MQ in two parts
    1. MQ on Platform
    2. Anypoint MQ connector in mule application
  • Anypoint MQ requires a separate Enterprise subscription and is not included in the Anypoint Platform trial version.
  • So for using MQ, you need to have an Enterprise subscription.
  • On the Anypoint platform, we need to create MQ, which can be used as Queue or DLQ.

Setup:

Login to your Anypoint account and select Anypoint MQ.

There are 3 options available:
1. Queue:

  • It’s created when there is no need to process the messages in the order in which they are stored in the MQ.

2. Exchange :

  • It’s created when there is a need to send one message to one or more applications.
  • It’s nothing but broadcasting a message.

3. FIFO Queue :

  • It’s created when there is a restriction to process the messages in the same order in which they are stored in the MQ.
  • It delivers each message to only one consumer and exactly once.

To create a normal queue, select queue from 3 options. It will open below the window. You just have to enter the name for the queue. If you want, you can change the message TTL. By default it’s 7 days. It shows how long unprocessed messages will stay in the queue after TTL time that message will be deleted.

Create one more queue which will act as DLQ for the above MQ.

For assigning DLQ for ang queue, goto that main queue config (in this case click on mq-demo). Then enable the “Assign Dead Letter Queue” and select queue name which we want to add as DLQ for this Queue(selected mq-demo-DLQ). Using “delivery attempts before reroute” option you can also decide how many times you want to attempt the delivery of a message before sending it to DLQ (in this case, it’s one time, if message is failed then it’s sent to DLQ)
How this DLQ is used is added in the next part of the blog. Here we will just create the DLQ.

To create a FIFO Queue select fifo queue option and similar to the normal queue fifo queue is created. In this queue messages will be processed in the order they are stored in the queue.

Create one more normal queue mq-demo1 with the default configuration.

To send a message in that queue you can use the Message sender option. Add a message in the payload section. You can also select the type of payload from drop down which are text, CSV, JSON you can also delay the delivery of message by adding the required value in the Delivery delay section.

Once the message is sent it will be stored in the mq-demo queue. You can go to the message browser to see all messages stored in that queue. Click on get messages to see those messages.

To create an Exchange, click on exchange. It will open the following configuration for the new exchange.

  • Add a name to that exchange as ID.
  • Select the queue name to which you want to broadcast the messages from this exchange.
  • For adding a queue to exchange it has to be a normal queue. As you can see below, in the options you can’t see the FIFO queue which we created.
  • 2 queues are added to this exchange queue that is mq-demo and mq-demo1.

If you go to the config of Exchange Mq-demo-exchange, you can see 2 options bind and unbind. Queues that are already bound to this exchange have the option to unbind. so that you can unbind any queue at any time. With bind, you can also bind any queue to this exchange.

Similar to normal queue exchange also has a message sender option from where you can send messages. These messages will be sent to all the queues which are bound to this exchange.

To see that message click on view message. In the below screenshot as you can see the same message is sent to both the queues which are bound to this exchange. Those are mq-demo and mq-demo1.

To see how can we used these MQ with Mule 4 Applications using Anypoint MQ Connector and functioning of DLQ you can use the following link : Anypoint MQ Connector

--

--