Wednesday, 5 October 2016

Publish and Subscribe Scenario

Step1:-
Create a flow like below Publish Messageflow
MQInputNode--->ComputeNode----->Publication Node

Configuration on Nodes:-
MQInputNode:-
Queuename: PublishQueue
Input Message Parsing: XMLNSC

ComputeNode:-

   SET OutputRoot.MQMD.Format =  'MQFMT_RF_HEADER_2';
 SET OutputRoot.MQRFH2.(MQRFH2.Field)version = 2;
 SET OutputRoot.MQRFH2.(MQRFH2.Field)Format = 'MQSTR';
 SET OutputRoot.MQRFH2.(MQRFH2.Field)NameValuCCSID=1208;
 SET OutputRoot.MQRFH2.psc.Command='Publish';
 SET OutputRoot.MQRFH2.psc.Topic = InputRoot.XMLNSC.publish.topic;
 Declare PTR REFERENCE to OutputRoot.MQRFH2;
 Detach PTR;
 attach PTR TO OutputRoot.MQMD AS NEXTSIBLING ;
 SET OutputRoot.XMLNSC.data.info = InputRoot.XMLNSC.publish.info;

Publication Node:-
No configuration needed.

Test Input:-
 <publish><topic>Bhanu</topic><info>Sample</info></publish> Put this Message in  PublishQueue
to publish

Step2:-
Create a flow like below Subscribe Messageflow
MQInputNode--->ComputeNode----->MQOutput Node

Configuration on Nodes:-
MQInputNode:-
Queuename: Subscription
Input Message Parsing: XMLNSC

ComputeNode:-

   SET OutputRoot.MQMD.Format =  'MQFMT_RF_HEADER_2';
 SET OutputRoot.MQRFH2.(MQRFH2.Field)version = 2;
 SET OutputRoot.MQRFH2.(MQRFH2.Field)Format = 'MQSTR';
 SET OutputRoot.MQRFH2.(MQRFH2.Field)NameValuCCSID=1208;
 SET OutputRoot.MQRFH2.psc.Command ='RegSub';
 SET OutputRoot.MQRFH2.psc.Topic = InputRoot.XMLNSC.subscribe.topic;
 SET OutputRoot.MQRFH2.psc.QName = 'RegSub';
 SET OutputRoot.MQRFH2.psc.QMgrName ='TEST';
DECLARE PTR REFERENCE TO OutputRoot.MQRFH2;
 Detach PTR;
 attach PTR TO OutputRoot.MQMD AS NEXTSIBLING ;

MQOutput Node:-
Queuename: SYSTEM.BROKER.CONTROL.QUEUE 

Test Input:-
<subscribe><topic>Bhanu</topic></subscribe> Put this Message in  Subscription
to Subscribe.

Objects to be Created:-
Create PublishQueue,Subscription,RegSub as three queues in MQ for testing

Direction to Test:-
First put the message in Subscription and then in the  PublishQueue, then you can see the message in RegSub queue due to publish and subscribe properties configured in message flow.

Tuesday, 4 October 2016

Global Cache PUT & GET

Global Cache
IBM Integration Bus provides an out of the box caching mechanism based on WebSphere eXtreme Scale.WebSphere eXtreme Scale provides a scalable, in-memory data grid. The data grid dynamically caches, partitions, replicates, and manages data across multiple servers.

This cache can be used to store reference data that are regularly accessed or to hold a routing table.

The cache is not enabled by default and it is really easy to enable it: the default configuration is activated by setting a configuration parameters through the IBM Explorer administration tool.
To activate the cache across different Integration Node instances, a XML configuration file (templates are provided) has to be defined.

Specialized skills in extremes scale is not necessary in order to use the cache. There is however two important cache components that may be good to know

Catalog servers
component that is embedded in an integration server and that controls placement of data and monitors the health of containers. You must have at least one catalog server in your global cache.
Container servers
component that is embedded in the integration server that holds a subset of the cache data. Between them, all container servers in the global cache host all of the cache data at least once. If more than one container exists, the default cache policy ensures that all data is replicated at least once. In this way, the global cache can cope with the loss of container servers without losing data.
Map
A data structure that maps keys to values. One map is the default map, but the global cache can have several maps.
Each execution group can host a WebSphere XS catalog server, container server, or both. Additionally, each execution group can make a client connection to the cache for use by message flows. The global cache works out of the box, with default settings, and no configuration -- you just switch it on! You do not need to install WebSphere XS alongside the broker, or any other additional components or products.

Scenario:-
Put And Get Key,Values in Global Cache


Write the below code in JCN
MbMessage outMessage = new MbMessage(inMessage);
                                    outAssembly = new MbMessageAssembly(inAssembly, outMessage);
// ----------------------------------------------------------
            // Add user code below
MbGlobalMap map = MbGlobalMap.getGlobalMap();
           
MbElement inParser = inAssembly.getMessage().getRootElement().getLastChild();
String key = "";
if(inParser.getFirstElementByPath("Input/key") != null)
{
key = inParser.getFirstElementByPath("Input/key").getValue().toString();
}
                                                     
MbElement outParser = outAssembly.getMessage().getRootElement().getLastChild ();
outParser.getLastChild().detach();
MbElement result = outParser.createElementAsLastChild(MbElement.TYPE_NAME, "Result", null);
                                   
if(!map.containsKey(key))
{
String value = "";
if(inParser.getFirstElementByPath("Input/value") != null)
      {
value = inParser.getFirstElementByPath("Input/value").getValue().toString();
      }
      map.put(key, value);
result.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "status", "Key = "+key + "inserted Successful in Global Cache");
      }
      else
      {
      Object value = map.get(key);             
                                          result.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Key", key);
result.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Value", value);
                                    }
Input Messages:-
//<Input><key>Bhanu</key><value>2032</value></Input>
//<Input><key>Key1</key></Input>
Set below Properties in MQ:-

Now the obtained OutPut Structure will look like:-
Global Cache with Grids Code:-

MbGlobalMap map = MbGlobalMap.getGlobalMap("grid1");
MbGlobalMap mapWithGrid2 = MbGlobalMap.getGlobalMap("grid2");
MbElement inParser = inAssembly.getMessage().getRootElement().getLastChild();
String key = "", value = "";
if(inParser.getFirstElementByPath("Input/key") != null)
{
key = inParser.getFirstElementByPath("Input/key").getValue().toString();
}
if(inParser.getFirstElementByPath("Input/value") != null)
{
value = inParser.getFirstElementByPath("Input/value").getValue().toString();
}
map.put(key, value);
mapWithGrid2.put(key, value);
Object dataFromGrid1 = map.get(key);
Object dataFromGrid2 = mapWithGrid2.get(key);