IBM API Connect Tutorial: Part-4 Integrate MQ with API Connect

IBM API Connect Tutorial: Part-4 Integrate MQ with API Connect

Here, I’ll write a tutorial on how to integrate IBM MQ with IBM API Connect v2018. The same is valid for v10 as well. So far, IBM has not povided us with any in built policy to integrate with MQ. However, MQ integration is very crucial for any enterprise. In this tutorial, I’ll cover how we can integration API Connect with MQ. We’ll follow the same custom extension framework that I have explained in my previous article on creating custom gateway extension of crypto object. We don’t have to always depend on IBM to deliver such features.

If you have not read my previous articles on APIC, please go through those:

Use Case

Before proceeding, let’s build the a use case for this tutorial to integrate MQ with API Connect. We’ll keep it very simple. Let’s expose a REST API that will accept a JSON payload from user and then it’ll persist the same into a MQ Queue.

Following will be our input data:

After successful execution, we would like to see the same message in the queue.

Assumption

I am assuming that you already have installed or have access to MQ. In my POC, I have installed IBM MQ in my laptop where I am also running the APIC LTE.

Creating the CLI script for MQ Queue Manager

There is no inbuilt policy for MQ Queue Manager connectivity in APIC. We are also not supposed to create Datapower objects manually in the APIC domain. Hence, we’ll to write a custom gateway extension containing the CLI commands to create a MQ Queue Manager object in the APIC domain of Datapower Gateway. Now, most of us are unsure of the syntax and how to use such CLI commands in Datapower. Like I showed in previous article, let’s do the easy hack.

  • Let’s login to any application domain (other than the APIC domain)
  • In this domain, let’s create a Queue manager object. I have used below configuration
IBM MQ Queue Manager Object in Datapower
IBM MQ Queue Manager Object in Datapower
  • After saving the above configuration, we’ll go to File Management and expand the config folder. There’ll be a file with the name of Datapower domain itself. Let’s open the file.
Datapower domain configuration
Datapower domain configuration
  • In this .cfg file, let’s search for the object that we just created. Basically, this file contains all the CLIs of the objects created in Datapower from GUI.
Datapower CLI script to create the Queue Manager Object
Datapower CLI script to create the Queue Manager Object
  • We’ll now copy the above commands that are used to create the MQ Queue Manager object. Our CLI script will be as follows:
  • I have masked my IP with x.x.x.x; please replace with your IP when you test.
  • Now, switch to the APIC domain in Datapower and head to File Management. Expand the temporary\config folder.
  • There will be quite a few files with names starting with a number. Note the highest number. For example, in the below snippet, you can see the highest number is 30.
APIC Domain configuration sequence
APIC Domain configuration sequence
  • We’ll now save the CLI script (that we copied above) with a number greater than the number present above. For example, I’ll save the script with a name 40.gw_ext_mq_qm.cfg
  • We’ll create a folder C:\apigwextqm and save the 40.gw_ext_mq_qm.cfg files in this folder.
  • Next, we will right click on this .cfg file and add it to a zip file named apigwextqm.zip

Create Gateway Extension

  • Now, open the command prompt and execute following command to login to API management using admin user.
  • Thereafter, execute the following command to create the gateway extension
  • Upon successful execution, it will give an output like:
  • We can also run the following command and check the output to confirm that the gateway extension is actually created
  • Upon successful execution, it will give an output like:
  • Apply the extension to the gateway server by restarting the API Connect gateway service object. Complete the following steps on each Gateway server in the Gateway service.
    • Log in to the Datapower (https://localhost:9091/dp/login.xml); switch to the domain reserved for API Connect
    • Search for API Connect Gateway Service
    • Set the Administrative State to disabled.
    • Apply the changes.
    • Set the Administrative State to enabled.
    • Apply the changes.

Verify the just created MQ QM objects

In the same APIC domain, let’s search for Queue Manager and see the object we just created using CLI commands:

Let’s build the API

Now, the easy part i.e. to build an API with a gateway script in assembly that puts the input message to the MQ. Following is the swagger for this API:

Publish & Test the API

  • Import the above swagger in API designer toolkit. In the assemble section of the API Designer, click on red encircled play button to publish the above API. Wait for the deployment to complete
Publish the API
Publish the API
  • Click on the test button. Please refer to the red encircled button below.
Test the API from the designer toolkit
Test the API from the designer toolkit
  • A new pane/sub-window will open on the left on top of the policy pallet. Select the operation
APIC Designer Toolkit Test pane
APIC Designer Toolkit Test pane
  • Scroll down; generate data and click on Invoke button.
  • It’ll invoke the API. The result will also be shown in the same pane
API LET Test/Invoke Result
API LET Test/Invoke Result
  • Now, let’s open the MQ Explorer and verify whether we have received the same message that we have sent as input.
Message got successfully persisted in MQ Queue
Message got successfully persisted in MQ Queue

Conclusion

Well, that’s it for today. We just learnt how to integrate MQ with APIC seamlessly. Stay tuned!

Reference

163

6 Responses

  1. Juan Parra
    November 21, 2021
    • Sadruddin Md
      November 27, 2021
  2. Sohail Ahmed
    December 9, 2021
    • Sadruddin Md
      December 9, 2021
  3. Icham
    February 3, 2022
    • Sadruddin Md
      February 12, 2022

Write a response

This site uses Akismet to reduce spam. Learn how your comment data is processed.