Anypoint MQ on Anypoint Platform
- August 05, 2021
Anypoint MQ provides publish-subscribe messaging to Mule apps using the Anypoint MQ cloud service. You can use this tool to send data between two applications or with multiple applications.
MQ can be used as Queue or DLQ. Queue temporarily stores 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’re sent to DLQ. As in queue, DLQ also temporarily stores the messages.
MQ has two parts:
- MQ on Anypoint Platform
- Anypoint MQ connector in a Mule application
Anypoint MQ requires a separate Enterprise subscription and isn’t included in the Anypoint Platform trial version. So, to use MQ, you’ll need an Enterprise subscription.
On the Anypoint Platform, we need to create MQ, which can be used as Queue or DLQ.
Set up
Log in to your Anypoint account and select Anypoint MQ.
You’ll see three available options:
- Queue:
- Created when there’s no need to process the messages in the order in which they are stored in the MQ
- Exchange:
- Created when there’s a need to send one message to one or more applications
- Simply broadcasts a message
- FIFO Queue:
- Created when there’s a restriction to process the messages in the same order in which they’re stored in the MQ
- Delivers each message to only one consumer and exactly once
To create a normal queue, select “Queue.” It will open below the original window. Enter the name for the queue.
If you want, you can change the message TTL that shows how long unprocessed messages will stay in the queue. By default, it’s seven (7) days. After the specified TTL, the message will be deleted.
Create another queue that will act as DLQ for the above MQ.
To assign a DLQ for any queue, go to the queue’s main configuration (in this case, click mq-demo). Then enable “Assign Dead Letter Queue” and select the queue name you want to add as a DLQ (mq-demo-DLQ). Using the “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).
To create a FIFO queue, select the “FIFO Queue” option. In this queue, messages will be processed in the order they’re stored in the queue.
Create another 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 the dropdown. The options are text, CSV and JSON.
You can 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. Go to the Message browser and click Get messages to see all messages stored in that queue.
To create an exchange, click on Exchange. It will open the following configuration:
- Add a name to that exchange as the ID
- Select the queue name to which you want to broadcast the messages from this exchange
- To add a queue to the exchange, it must be a normal queue — as you can see below, the options don’t show the previously created FIFO queue
- Two queues have now been added to this exchange queue:
- mq-demo
- mq-demo1
If you go to the configuration of this exchange — mq-demo-exchange — you’ll see two options:
- Bind
- 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 the bind option, you can also bind any queue to this exchange.
Like a normal queue exchange, a FIFO queue also has a Message sender option from where you can send messages. These messages will be sent to all the queues bound to this exchange.
To see that message, click View message. The screenshot below shows that the same message has been sent to both queues — mq-demo and mq-demo1 — bound to this exchange.
Go to Anypoint MQ Connector to see how you can use MQ with Mule 4 applications using Anypoint MQ Connector and how DLQ functions.
— By Kishori Patil