Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Anypoint MQ on CloudHub

DZone's Guide to

Anypoint MQ on CloudHub

MQ, or message queue service, is a widely used concept in integration. Learn how to create and configure a queue in Mule Flow with CloudHub.

· Integration Zone
Free Resource

Share, secure, distribute, control, and monetize your APIs with the platform built with performance, time-to-value, and growth in mind. Free 90 day trial 3Scale by Red Hat

Queue is one of the most widely used concepts in the integration world. I am one of the biggest fans (and a developer, as well) of Mule ESB. In this product, we have so many amazing features which can be used quickly, and the learning curve is less.

I am going to pick Anypoint queue for the explanation in this article. This article is mainly focused on the use and how to make this queue on cloud more effective.

Queue Creation on Anypoint Platform

First of all, you should have the license to use MQ feature available in the CloudHub platform. Once you have the license, you go to the top left of the screen from where you can see MQ as an option. Select MQ and you will land on the below page.  On this page, you will see a + sign on the top right corner. Once you click it, you will see the option to create a queue; here you select Queue.

You will see the below pop up while creating a new group. You have to give a unique name. You can manipulate the TimetoLive or Lock TTL. The Time to Live feature is to tell you the amount of time one particular message will survive in this queue.

QueueCreation-1

There are some additional out-of-the-box features as well. You can enable encrypting of all your incoming messages. Second, you can utilize the Dead Letter inbuilt functionality. You do not need to write any extra logic to move messages to DL queue. To elaborate more on this DL queue is whenever a normal processing from queue fails then it has to be moved a DL queue from where it will be reprocessed. If you see below you can put configure the number of retries as well. You just mention the queue name where you want to send the message from the normal queue. It will be moved to a DL after a certain number of retries.

QueueCreation-2

Once you are done with the creation, you can see the below page which will list all the queues name which has been created in each environment. Right now you are in the Destination tab. 

Queue Creation

Now, to make it usable from Anypoint studio, you have to create a client. You can create "n" number of clients who will be using these queues. For PoC purposes, you can create a single client here.

ClientApp Creation

How to Use the Queue in Mule Flow

Now that our queue is properly configured, we need to focus on how to use it. You can go to the studio and search this Anypoint MQ component:

Image title

Once you have placed the connector in the flow, you have to configure the connector. You have to provide URL, Client App ID, and Client Secret.

QueueCode

For these values, please refer to pic-3 and pic-4. Pic-3 will provide you the URL value which you need to use. Similarly, you have to use values ID and Secret key as shown in pic-4 of this article. Each client which you create on CloudHub will have one pair of AppID and Client secret values. You can use the same queue by having two separate clients configured on CloudHub.

Currently, the message types which is being supported by Anypoint MQ are text, CSV, and JSON.

Now there are four operations available in the connector component in the Mule studio:

  • Publish: This is to place any message to the queue. You have to provide one value which will act as a Message ID in the queue for that particular message.

  • Consume: This is to consume message from the queue. You have to put the queue name as the value for the Destination field.

  • ACK: If you want to delete the message completely from the queue after reading.

  • NACK: If you want to retain the message after reading. The message would be available for reading by the all the clients.

One more catch is that you have to select Acknowledgement Mode as manual to make this ack and nack work properly.

I hope enough information has been provided to make good use of the queue. Stay tuned for more implementation side details.

Discover how you can achielve enterpriese agility with microservices and API management

Topics:
tutorial ,integration ,anypoint studio ,mule esb ,cloudhub ,mule flow

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}