+

Search Tips | Advanced Search

Communicating between two IBM MQsystems on IBM i

This coding example illustrates how to set up two IBM MQ for IBM i systems, using CL commands, so that they can communicate with each other.

The systems are called SYSTEMA and SYSTEMB, and the communications protocol used is TCP/IP.

Carry out the following procedure:
  1. Create a queue manager on SYSTEMA, calling it QMGRA1.
    CRTMQM   MQMNAME(QMGRA1) TEXT('System A - Queue +
    Manager 1') UDLMSGQ(SYSTEM.DEAD.LETTER.QUEUE)
    
  2. Start this queue manager.
    STRMQM   MQMNAME(QMGRA1)
    
  3. Define the IBM MQ objects on SYSTEMA that we need to send messages to a queue manager on SYSTEMB.
    /* Transmission queue */
    CRTMQMQ  QNAME(XMITQ.TO.QMGRB1) QTYPE(*LCL) +
    MQMNAME(QMGRA1) TEXT('Transmission Queue +
    to QMGRB1') MAXDEPTH(5000) USAGE(*TMQ)
    
    /* Remote queue that points to a queue called TARGETB        */
    /* TARGETB belongs to queue manager QMGRB1 on SYSTEMB        */
    CRTMQMQ  QNAME(TARGETB.ON.QMGRB1) QTYPE(*RMT) +
    MQMNAME(QMGRA1) TEXT('Remote Q pointing +
    at Q TARGETB on QMGRB1 on Remote System +
    SYSTEMB') RMTQNAME(TARGETB) +
    RMTMQMNAME(QMGRB1) TMQNAME(XMITQ.TO.QMGRB1)
    
    /* TCP/IP sender channel to send messages to the queue manager on SYSTEMB*/
    CRTMQMCHL CHLNAME(QMGRA1.TO.QMGRB1) CHLTYPE(*SDR) +
    MQMNAME(QMGRA1) TRPTYPE(*TCP) +
    TEXT('Sender Channel From QMGRA1 on +
    SYSTEMA to QMGRB1 on SYSTEMB') +
    CONNAME(SYSTEMB) TMQNAME(XMITQ.TO.QMGRB1)
    
  4. Create a queue manager on SYSTEMB, calling it QMGRB1.
    CRTMQM   MQMNAME(QMGRB1) TEXT('System B - Queue +
    Manager 1') UDLMSGQ(SYSTEM.DEAD.LETTER.QUEUE)
    
  5. Start the queue manager on SYSTEMB.
    STRMQM   MQMNAME(QMGRB1)
    
  6. Define the IBM MQ objects that we need to receive messages from the queue manager on SYSTEMA.
    /* Local queue to receive messages on */
    CRTMQMQ  QNAME(TARGETB) QTYPE(*LCL) MQMNAME(QMGRB1) +
    TEXT('Sample Local Queue for QMGRB1')
    
    /* Receiver channel of the same name as the sender channel on SYSTEMA */
    CRTMQMCHL CHLNAME(QMGRA1.TO.QMGRB1) CHLTYPE(*RCVR) +
    MQMNAME(QMGRB1) TRPTYPE(*TCP) +
    TEXT('Receiver Channel from QMGRA1 to +
    QMGRB1')
    
  7. Finally, start a TCP/IP listener on SYSTEMB so that the channel can be started. This example uses the default port of 1414.
    STRMQMLSR MQMNAME(QMGRB1)
    

You are now ready to send test messages between SYSTEMA and SYSTEMB. Using one of the supplied samples, put a series of messages to your remote queue on SYSTEMA.

Start the channel on SYSTEMA, either by using the command STRMQMCHL, or by using the command WRKMQMCHL and entering a start request (Option 14) against the sender channel.

The channel should go to RUNNING status and the messages are sent to queue TARGETB on SYSTEMB.

Check your messages by issuing the command:
WRKMQMMSG QNAME(TARGETB) MQMNAME(QMGRB1).
Parent topic: Manage IBM MQ for IBM i using CL commands

Last updated: 2020-10-04