Global Cache in IBM ACE 12

Adil Abdullah
5 min readJul 18, 2022

--

What to cover:

1. Implement cache on integration node.

2. Implement cache on integration server.

3. Make integration server as catalogue and container.

4. Create multi instance catalogue server.

5. Create multi instance container server.

Step 1:

Create new application project and named as what ever you want.

Step 2:

In my case I’ve named application as CacheApp and create 2 flows named CacheUpdate and CheckCache.

Step 3:

Create java project inside you IBM App connect Cache application project. And in Java create package called com.java.cache and inside package create class called CacheUtil.java.

Step 4:

Write below java code on CacheUtil.java class which you’ve created on step 3.

Java Code

package com.java.cache;

import com.ibm.broker.plugin.MbElement;

import com.ibm.broker.plugin.MbException;

import com.ibm.broker.plugin.MbGlobalMap;

public class CacheUtil {

/**

* Method to get a value from Global Cache using map name and key

*/

public static String getValue(String strKey,String mapName) {

String strValue = null;

MbGlobalMap globalMap = null;

try

{

globalMap = MbGlobalMap.getGlobalMap(mapName);

strValue = (String) globalMap.get(strKey);

}

catch(MbException mbe)

{

System.out.println(mbe.getMessage());

mbe.printStackTrace();

}

return strValue;

}

/**

* Method to add all the key-value pairs for a map in Global Cache

*/

public static Boolean addMap(MbElement elmMap,String mapName) {

String strValue = null;

String strKey = null;

MbGlobalMap globalMap = null;

try

{

elmMap = elmMap.getFirstChild();

globalMap = MbGlobalMap.getGlobalMap(mapName);

MbElement elmEntry = elmMap.getNextSibling();

while (elmEntry != null) {

strKey = elmEntry.getFirstChild().getValueAsString();

strValue = elmEntry.getValueAsString();

if(globalMap.containsKey(strKey)) {

globalMap.update(strKey,strValue);

} else {

globalMap.put(strKey, strValue);

}

elmEntry = elmEntry.getNextSibling();

}

}

catch(MbException mbe) {

System.out.println(mbe.getMessage());

mbe.printStackTrace();

return Boolean.FALSE;

}

return Boolean.TRUE;

}

/**

* Method to add a key-value pair to a map in Global Cache

*/

public static String addUpdateKey(String strKey, String strValue,String mapName) {

MbGlobalMap globalMap = null;

try

{

globalMap = MbGlobalMap.getGlobalMap(mapName);

if(globalMap.containsKey(strKey)) {

globalMap.update(strKey,strValue);

} else {

globalMap.put(strKey, strValue);

}

}

catch(MbException mbe) {

System.out.println(mbe.getMessage());

mbe.printStackTrace();

return mbe.getMessage();

}

catch(Exception ex) {

System.out.println(ex.getMessage());

ex.printStackTrace();

return ex.getMessage();

}

return “1”;

}

}

Step 5:

Below is the message flow of CacheUpdate which we have created in step 2. The purpose of this flow to read file where we placed data of configuration parameters (Other than file be it database for storing values. It totally depends on you.) The data read from file then parse and put on Java cache collection through java method on ESQL. The java method with complete code defined in previous step. The is API message flow endpoint is defined on first (HTTP input node) when we hit endpoint and the data stored on file will be updated on cache and return successful response. Incase any failure then exception is printed with reason.

ESQL Code for Cache Update

CREATE COMPUTE MODULE ReadFile_UpdateCache

CREATE FUNCTION Main() RETURNS BOOLEAN

BEGIN

SET setCacheValue(‘db-schema’,’TEST1',’AdilMap’);

RETURN TRUE;

END;

CREATE PROCEDURE setCacheValue(IN chrKey CHARACTER,

IN chrVal CHARACTER,

IN mapCache CHARACTER)

RETURNS CHARACTER

LANGUAGE JAVA

EXTERNAL NAME “com.java.cache.CacheUtil.addUpdateKey”;

END MODULE;

Step 6:

Below is the message flow of CheckCache which we created in step 2. This is also HTTP API message flow endpoint is defined on first (HTTP input node) then try catch for exception handle then ESQL node for getting value from cache stored against particular key to check weather cache is working on not and what value against this key is present on cache. The last node HTTP reply to return successful response incase no exception is generated during runtime of flow. If any exception during flow runtime then it goes to Failed response ESQL node and exception is log and return with reason as service response.

ESQL Code for Get Cache Value

CREATE COMPUTE MODULE CheckCache_GetValue

CREATE FUNCTION Main() RETURNS BOOLEAN

BEGIN

DECLATE DB_SCHEMA CHARACTER ‘’;

SET DB_SCHEMA =getCacheValue(‘db-schema’,’AdilMap’);

SET OutputRoot.JSON.Data.ResponseCode=’00';

SET OutputRoot.JSON.Data.ResponseDesc= DB_SCHEMA; — cacheValue;

RETURN TRUE;

END;

CREATE PROCEDURE getCacheValue(IN chrKey CHARACTER,

IN mapCache CHARACTER)

RETURNS CHARACTER

LANGUAGE JAVA

EXTERNAL NAME “com.java.cache.CacheUtil.getValue”;

END MODULE;

Step 7:

In this step we create an integration node named as LearningNode using IBM App connect command console.

mqsicreatebroker <integration node>

Now start newly created integration node.

mqsistart <integration node>

Step 8:

Now create 2 integration server named as LearnEG1 and LearnEG2 on integration node LearningNode as seen in below commands.

mqsicreateexecutiongroup <integration node> -e <EG name>

Step 9:

Open server.conf.yaml for LearnEG1 file exist on this path C:\ProgramData\IBM\MQSI\components\LearningNode\servers\LearnEG1 and paste below mention GlobalCache section configuration under ResourceManagers section in server.conf.yaml file.

GlobalCache section:

GlobalCache:

cacheOn: true

cacheServerName: MyCatalogServer1

catalogServiceEndPoints: ‘server1.mycompany.com:2800,server2.mycompany.com:2800’

catalogDomainName: WMB_MyCacheDomain

catalogClusterEndPoints: >-

MyCatalogServer1:server1.mycompany.com:2803:2801,MyCatalogServer2:server2.mycompany.com:2803:2801

enableCatalogService: true

enableContainerService: true

enableJMX: true

listenerHost: server1.mycompany.com

listenerPort: 2800

Step 10:

Open server.conf.yaml for LearnEG2 file exist on this path C:\ProgramData\IBM\MQSI\components\LearningNode\servers\LearnEG2 and paste below mention GlobalCache section configuration under ResourceManagers section in server.conf.yaml file.

GlobalCache section:

GlobalCache:

cacheOn: true

cacheServerName: MyCatalogServer2

catalogServiceEndPoints: ‘server1.mycompany.com:2800,server2.mycompany.com:2800’

catalogDomainName: WMB_MyCacheDomain

catalogClusterEndPoints: >-

MyCatalogServer1:server1.mycompany.com:2803:2801,MyCatalogServer2:server2.mycompany.com:2803:2801

enableCatalogService: true

enableContainerService: true

enableJMX: true

listenerHost: server2.mycompany.com

listenerPort: 2800

Step 11:

Restart both EG using IBM App Connect command console using below commands.

mqsistopmsgflow <integration node> -e <eg name>

mqsistartmsgflow <integration node> -e <eg name>

Step 12:

Deploy CacheApplication which we created in step 1 along with Java project which reside inside the application now deploy in any of the EG you created in step 8.

--

--

Adil Abdullah
Adil Abdullah

Written by Adil Abdullah

Currently working as Full stack Java developer at Contour Software at their Easit AB division part of Jonas group. Working on Java and IBM stack.

No responses yet