Friday, 4 March 2016

IIB Java Compute Node to retrieve database information and convert it to COBOL.


Often several of my students have asked me to show a scenario on how to retrieve database records using java compute node.
Some others have asked, how to build the complete message tree from scratch in JCN.
And some others have asked how to build a COBOL result records in JCN.

I have put all three of them together to demo a simple scenario.

Pre-requisites :-

  1. In my classes I have shown you, how to setup DB2 sample database. We will use the same EMPLOYEE table from that database.
  2. In my database classes I have shown you how to create configurable services and ODBC/JDBC DSNs. We will use the same JDBC type 4 drivers with configurable service defined.
  3. You should have the EMPLOYEE.cpy COBOL and inputmessage XML file which I have shared in the class to successfully run this example.

Steps to implement this lab :-

  1. Create an Application and create a model using supplied COBOL file. You would get EMPLOYEE.xsd generated by the DFDL Message Model editor
  2. The generated EMPLOYEE.xsd would look like :-
  3. Create a simple message flow :- MQInput Node -> Java Compute Node -> MQOutput Node
  4. Set MQInput properties 
    1. Basic :- Give the input queue name 
    2. Input Message Parsing :- XMLNSC domain
  5. Set MQOutput properties 
    1. Basic :- Give the output queue name
  6. Set Java Compute (choose to create a message tree without copying input tree)
    1. Import the following as shown in the figure :- 
    2. Use the following two methods :- Copy Message Headers & Evaluate method  

  7. Deploy the flow for a quick test.
  8. Put the test input message with the employee number something like <EmployeeID>000010</EmployeeID>
  9. See the output in COBOL format like :-
000010CHRISTINE   IHAAS        A00         3978        1995-01-01  PRES        18          F           1963-08-24  152750.00   5000.00     4220.00  

Friday, 29 January 2016

WebSphere MQ Cluster Setup

This demo considers creating a cluster environment with four queue managers in which two of them act as full repositories (QM_FR1,QM_FR2) and other two act as partial repositories (QM_PR1,QM_PR2). The full repositories will communicate with each other and the partial repositories will communicate with any of the full repositories using the defined cluster sender receiver channels.

       

  1. Create a queue manger QM_FR1, listener, full repository by using the following commands
    1. CRTMQM QM_FR1<--to create a queue manager
    2. STRMQM QM_FR1<--to start a queue manage
    3. RUNMQSC QM_FR1<-- to perform some administrative tasks
      1. ALTER QMGR REPOS('CLUSTER1')<--To create a cluster and make the queue manager as full repositories
      2. DEFINE LISTENER(L1) TRPTYPE(TCP) CONTROL(QMGR) PORT(1450)<--to create a listener in the QM_FR1
      3. START LISTENER(L1)<-- to start listener
  2. Create a queue manger QM_FR2, listener,cluster sender and cluster receiver channels and make them as full repository by using the following commands
    1. CRTMQM QM_FR2<--to create a queue manager
    2. STRMQM QM_FR2<--to start a queue manager
    3. RUNMQSC QM_FR2<-- to perform some administrative tasks
      1. ALTER QMGR REPOS('CLUSTER1')<--To create a cluster and make the queue manager as full repositories
      2. DEFINE LISTENER(L2) TRPTYPE(TCP) CONTROL(QMGR) PORT(1451)<--to create a listener in the QM_FR1
      3. START LISTENER(L2)<-- to start listener
  3. Define the cluster receiver channels for the queue managers QM_FR1 and QM_FR2
    1. DEFINE CHANNEL(TO.QM_FR1) CHLTYPE(CLUSRCVR) CONNAME('LOCALHOST(1450)') CLUSTER('CLUSTER1')<-----to create the cluster receiver channel in QM_FR1
    2. DEFINE CHANNEL(TO.QM_FR2) CHLTYPE(CLUSSDR) CONNAME('LOCALHOST(1451)') CLUSTER('CLUSTER1')<------to create the cluster sender channel in QM_FR1
  4. Define the cluster sender channel on the queue managers. The channel name must match that of the cluster sender channel on the full repository
    1. DEFINE CHANNEL(TO.QM_FR2) CHLTYPE(CLUSRCVR) CONNAME('LOCALHOST(1451)') CLUSTER('CLUSTER1')<----to create the cluster receiver channel in QM_FR2
    2. DEFINE CHANNEL(TO.QM_FR1) CHLTYPE(CLUSSDR) CONNAME('LOCALHOST(1450)') CLUSTER('CLUSTER1')<------to create the cluster sender channel in QM_FR2
  5. Create the queue manager QM_PR1, listener and make it as a partial repository by creating cluster sender and cluster receiver channels to full repository
    1. CRTMQM QM_PR1<------to create the queue manager
    2. RUNMQSC QM_PR1<-- to perform some administrative tasks
      1. DEFINE LISTENER(PRL1) TRPTYPE(TCP) CONTROL(QMGR) PORT(1452)<----to create the listener
      2. START LISTENER(PRL1)<------to start the listener
      3. DEFINE CHANNEL(TO.QM_PR1) CHLTYPE(CLUSRCVR) CONNAME('LOCALHOST(1452)') CLUSTER('CLUSTER1')<-------to create the cluster receiver channel in QM_PR1(partial repository)
      4. DEFINE CHANNEL(TO.QM_FR1) CHLTYPE(CLUSSDR) CONNAME('LOCALHOST(1450)') CLUSTER('CLUSTER1')<-------to create the cluster sender channel in QM_PR1(partial repository)
  6. Create the queue manager QM_PR2, listener and make it as a partial repository by creating cluster sender and cluster receiver channels to full repository
    1. CRTMQM QM_PR2<------to create the queue manager
    2. RUNMQSC QM_PR2<-- to perform some administrative tasks
      1. DEFINE LISTENER(PRL2) TRPTYPE(TCP) CONTROL(QMGR) PORT(1453)<----to create the listener
      2. START LISTENER(PRL2)<------to start the listener
      3. DEFINE CHANNEL(TO.QM_PR2) CHLTYPE(CLUSRCVR) CONNAME('LOCALHOST(1453)') CLUSTER('CLUSTER1')<-------to create the cluster receiver channel in QM_PR2(partial repository)
      4. DEFINE CHANNEL(TO.QM_FR2) CHLTYPE(CLUSSDR) CONNAME('LOCALHOST(1451)') CLUSTER('CLUSTER1')<-------to create the cluster sender channel in QM_PR1(partial repository)
  7. Create clustered queue in the QM_PR1 which is made available to other queue managers in the cluster
    1. RUNMQSC QM_PR1 <--to perform some administrative tasks
    2. DEFINE QLOCAL(CQ1) CLUSTER('CLUSTER1')
  8. Put a test message into the cluster queue CQ1 from other queue manager QM_FR1 using the command "AMQSPUT" as
    1. AMQSPUT CQ1 QM_FR1



Thursday, 21 January 2016

Creating different channel pairs in Websphere MQ using MQSC commands

We will consider to create different channel pairs on two different systems i.e., system1 and system2. For testing purpose System2 will have a queue manager named QM2 with a local Queue LQ2. Similarly System1 will have a queue manager named QM1 with a Remote Queue RQ pointing to QM2 LQ2 along with a transmission queue definition.


The following steps are mandatory before creating any channel pairs.
  1. Create and start the Queue manager in the System1
    1. CRTMQM QM1
    2. STRMQM QM1
  2. Create and start the Queue manager in the System2
    1. CRTMQM QM2
    2. STRMQM QM2
  3. Create a local queue in QM2
    1. RUNMQSC QM2
    2. DEFINE QLOCAL(LQ2)
  4. Create a transmission queue in the QM1
    1. RUNMQSC QM1
    2. DEFINE QLOCAL(TQ) USAGE(XMITQ)
  5. Create a remote queue in the QM1 which points to the local queue in the QM2
    1. DEFINE QREMOTE(RQ) RNAME(LQ2) RQNAME(QM2) XMITQ(TQ)
  6. Create a listener port so that the QM1 and QM2 will be able to communicate
    1. DEFINE LISTENER(QM1_LISTENER) TRPTYPE(TCP) PORT(1419) <- QM1
    2. DEFINE LISTENER(QM2_LISTENER) TRPTYPE(TCP) PORT(1420) <-QM2
    3. START LISTENER QM1_LISTENER
    4. START LISTENER QM2_LISTENER

The following are the steps to create SENDER AND REQUESTER channel pair
  1. Create a SENDER channel in QM1
    1. DEFINE CHANNEL(SDR_RQSTR) CHLTYPE(SDR) CONNAME('system2 IP address(the Qm2 port number )' ) xmitq(TQ)
  2. Create a REQUESTER channel in QM2
    1. DEFINE CHANNEL(SDR_RQSTR) CHLTYPE(RQSTR) CONNAME('system1 ip address(Qm1 port number)') TRPTYPE(TCP)
  3. Start the channels
The following are the steps to create SENDER AND RECEIVER channel pair
  1. Create a SENDER channel in the QM1
    1. DEFINE CHANNEL(SDR_RCVR) CHLTYPE(SDR) CONNAME('system2 IP address(the Qm2 port number )' ) XMITQ(LQ)
  2. Create a RECEIVER channel in QM2
    1. DEFINE CHANNEL(SDR_RCVR) CHLTYPE(RCVR) TRPTYPE(TCP)
  3. Start the channels
The following are the steps to create SERVER AND RECEIVER channel pair
  1. Create a SERVER channel in the QM1
    1. DEFINE CHANNEL(SVR_RCVR) CHLTYPE(SVR) CONNAME('system2 IP address(the Qm2 port number )' ) XMITQ(LQ)
  2. Create a RECEIVER channel in QM2
    1. DEFINE CHANNEL(SVR_RCVR) CHLTYPE(RCVR) TRPTYPE(TCP)
  3. Start the channels
The following are the steps to create SERVER AND REQUESTER channel pair
  1. Create a SERVER channel in the QM1
    1. DEFINE CHANNEL(SVR_RQSTR) CHLTYPE(SVR) CONNAME('system2 IP address(the Qm2 port number )' ) XMITQ(LQ)
  2. Create a REQUESTER channel in QM2
    1. DEFINE CHANNEL(SVR_RQSTR) CHLTYPE(RQSTR) CONNAME('system1 ip address(Qm1 port number)') TRPTYPE(TCP)
  3. Start the channels

Hopping a message WebSphere MQ

In this scenario we intend to send a message from system1 to system3 via system2, i.e., not directly but through hopping. We need three queue managers (QMGR1, QMGR2, QMGR3) in three different systems. When we put message in remote queue of system1 it hops through the remote queue of second queue and lands in local queue of system3. Inorder to achieve this, we need to create channels, listeners and queues, in each queue manager, as explained in the below hierarchy.

SYSTEM1:
SYSTEM2
SYSTEM3
1.QMGR1(queue manager)
1.QMGR2(queue manager)
1.QMGR3(queue manager)
2.LSTNR1(listener)
2.LSTNR2(listener)
2.LSTNR3(listener)
3.TRNSQ1(transmission queue)
3.TRNSQ2(transmission queue)
3.LQ(local queue)
4.RMTQ1(remote queue)
4.RMTQ2(remote queue)
4.QMGR2_TO_QMGR3(receiver channel)
5.QMGR1_TO_QMGR2(sender channel)
5.QMGR1_TO_QMGR2(receiver channel)
6.QMGR2_TO_QMGR3(sender channel)
Step by step instructions :-
  1. Create and start a  queue manager in all the three systems using the following commands
    1. CRTMQM QMGR1<------to create a queue manager
    2. STRMQM QMGR1<------to start a queue manager
  2. Create a listener,transmission queue,remote queue and a sender channel in system1 using the following commands
    1. RUNMQSC QMGR1 <-- opens a window to issue commands specific to the queue manager
    2. DEFINE LISTENER (LSTNR1) TRPTYPE (TCP) PORT(PORT NUMBER) <-- to create a listener
    3. DEFINE QLOCAL(TRNSQ1) USAGE(XMITQ) <-- to create a transmission queue
    4. DEFINE QREMOTE(RMTQ1) RNAME(RMTQ2) RQMNAME(QMGR2) XMITQ(TRNSQ1) <--to create remote queue
    5. DEFINE CHANNEL(QMGR1_TO_QMGR2) CHLTYPE(SDR)CONNAME('QMGR2_HOSTNAME(PORT NUMBER)')        XMITQ(TQ) <- to create sender channel
  3. Create a listener,transmission queue,remote queue,receiver channel, sender channel in system2 using following commands
    1. RUNMQSC QMGR2 <-- opens a command window to issue commands specific to the queue manager
    2. DEFINE LISTENER (LSTNR2) TRPTYPE (TCP) PORT(PORT NUMBER) <-- to create a listener
    3. DEFINE QLOCAL(TRNSQ2) USAGE(XMITQ) <-- to create a transmission queue
    4. DEFINE QREMOTE(RMTQ2) RNAME(LQ) RQMNAME(QMGR3) XMITQ(TRNSQ2) <-- to create remote queue
    5. DEFINE CHANNEL(QMGR1_TO_QMGR2) CHLTYPE(RVCR) TRPTYPE(TCP) <-- to create the receiver channel
    6. DEFINE CHANNEL (QMGR2_TO_QMGR3) CHLTYPE(SDR)CONNAME('QMGR3_HOSTNAME(PORT-                    NUMBER)') XMITQ(TRNSQ2) <- to create sender channel
  4. Create listener,receiver channel,local queue in system3 using following commands
    1. DEFINE LISTENER (LSTNR3) TRPTYPE (TCP) PORT(PORT NUMBER) <-- to create a listener
    2. DEFINE CHANNEL(QMGR2_TO_QMGR3) CHLTYPE(RVCR) TRPTYPE(TCP) <-- to create the receiver channel
    3. DEFINE QLOCAL(LQ) <-- to create the local queue
  5. Start the listener and channels in every system using the following commands
    1. START LISTENER(LISTENER_NAME)<----to start listener
    2. START CHANNEL(CHANNEL_NAME)<------to start the channel
  6. Put the message in remote queue of first system
    1. AMQSPUT RQ QMGR1 <-- after this type your message and double click enter
  7. Get the message from the system3
    1. AMQSGET LQ QMGR2 <-- you can see the message which is transmitted in the system1

Transferring a message from one queue manager to another one

In this scenario, we will create two queue managers QMGR1 AND QMGR2 in two different systems. The objective is to transfer a message from QMGR1 to QMGR2. We first need to create a local queue(LQ) in QMGR2 then we need to create a transmission queue (QMGR2) in QMGR1. We also need to create remote queue(RQ) on QMGR1 which points to the LQ of QMGR2. We need to create a sender channel in QMGR1 and receiver channel in QMGR2. When we put the message in remote queue (RQ) of QMGR1 it will appear in the local queue (LQ) of QMGR2.

The following steps were tested on windows system and the same would work in other platforms too.

  1. Create and start the queue manager in system 1
    1. CRTMQM QMGR1 <-- to create a queue manager
    2. STRMQM QMGR1 <-- to start a queue manager
  2. Create transmission queue and listener in system 1
    1. RUNMQSC QMGR1 <-- opens a command window to issue commands specific to the queue manager
    2. DEFINE QLOCAL(TQ) USAGE(XMITQ) <-- to create a transmission queue
  3. Create another queue manager in system 2 using the following commands
    1. CRTMQM QMGR2 <-- to create a queue manager
    2. STRMQM QMGR2 <-- to start a queue manager
  4. Create a local queue and receiver channel queue in system 2
    1. RUNMQSC QMGR2 <-- Use this command to issue MQSC commands to a queue manager  
    2. DEFINE QLOCAL(LQ) <-- to create the local queue
    3. DEFINE LISTENER (LISTENER_NAME) TRPTYPE (TCP) PORT(PORT NUMBER) <-- to create a listener
    4. DEFINE CHANNEL(QMGR1_TO_QMGR2) CHLTYPE(RCVR) TRPTYPE(TCP) <-- to create the receiver channel
  5. Create the remote queue and sender channel in system1
    1. RUNMQSC QMGR1 <--Use this command to issue MQSC commands to the queue manage
    2. DEFINE QREMOTE(RQ) RNAME(LQ) RMQNAME(QMGR2) XMITQ(TQ) <-- to create remote queue
    3. DEFINECHANNEL (QMGR1_TO_QMGR2) CHLTYPE(SDR) CONNAME('QMGR2_HOSTNAME(PORT NUMBER)')  XMITQ(TQ)<----to create sender channel
  6. NOTE:THE SENDER CHANNEL NAME AND RECIVER CHANNEL NAME SHOULD BE SAME. Now come out of RUNMQSC command by typing the command "END"
  7. Put the message in remote queue of system 1
    1. AMQSPUT RQ QMGR1 <-- after this type your message and double click enter
  8. Get the message from the local queue in system 2
    1. AMQSGET LQ QMGR2 <-- you can see the message which is transmitted in the system 1