Publish/subscribe hierarchy example: Scenario 1

Set up a publish/subscribe hierarchy topology using point-to-point channels with queue manager name alias.

About this task

These scenarios set up a publish/subscribe hierarchy in different ways to establish the connection between queue managers. These scenarios all use a parent queue manager called QM1, and two child queue managers called QM2, and QM3.

Scenario 1 is split into smaller sections to make the process easier to follow.

Scenario 1 part 1: Create the queue managers

Procedure

  1. Create and start three queue managers called QM1, QM2, and QM3 using the following commands:
    crtmqm -u SYSTEM.DEAD.LETTER.QUEUE QM1
    strmqm QM1
    
    crtmqm -u SYSTEM.DEAD.LETTER.QUEUE QM2
    strmqm QM2
    
    crtmqm -u SYSTEM.DEAD.LETTER.QUEUE QM3
    strmqm QM3
  2. Enable the queue manager publish/subscribe mode by using the following command on all three queue managers:
    ALTER QMGR PSMODE(ENABLED)

Scenario 1 part 2: Point-to-point channel connections

About this task

Establish point-to-point channel connections between queue managers using a queue manager alias with the same name as the parent queue manager.

Procedure

  1. Define a transmission queue and queue manager alias on QM2 to QM1. Define a sender channel to QM1 and a receiver channel for the sender channel created on QM1 for QM2:
    DEFINE QLOCAL(QM1.XMITQ) USAGE(XMITQ)
    
    DEFINE QREMOTE (QM1) RNAME('') RQMNAME(QM1) XMITQ(QM1.XMITQ)
    
    DEFINE CHANNEL('QM2.TO.QM1') CHLTYPE(SDR) CONNAME('localhost(9999)') XMITQ(QM1.XMITQ) TRPTYPE(TCP)
    
    DEFINE CHANNEL('QM1.TO.QM2') CHLTYPE(RCVR) TRPTYPE(TCP)
  2. Define a transmission queue and queue manager alias on QM3 to QM1. Define sender channel to QM1 and a receiver channel for the sender channel created on QM1 for QM3:
    DEFINE QLOCAL(QM1.XMITQ) USAGE(XMITQ)
    
    DEFINE QREMOTE (QM1) RNAME('') RQMNAME(QM1) XMITQ(QM1.XMITQ)
    
    DEFINE CHANNEL('QM3.TO.QM1') CHLTYPE(SDR) CONNAME('localhost(9999)') XMITQ(QM1.XMITQ) TRPTYPE(TCP)
    
    DEFINE CHANNEL('QM1.TO.QM3') CHLTYPE(RCVR) TRPTYPE(TCP)
  3. Define a transmission queue and queue manager alias on QM1 to QM2 and QM3. Define sender channel to QM2 and QM3, and a receiver channel for the sender channels created on QM2 and QM3 for QM1:
    DEFINE QLOCAL(QM2.XMITQ) USAGE(XMITQ)
    
    DEFINE QREMOTE (QM2) RNAME('') RQMNAME(QM2) XMITQ(QM2.XMITQ)
    
    DEFINE CHANNEL('QM1.TO.QM2') CHLTYPE(SDR) CONNAME('localhost(7777)') XMITQ(QM2.XMITQ) TRPTYPE(TCP)
    
    DEFINE CHANNEL('QM2.TO.QM1') CHLTYPE(RCVR) TRPTYPE(TCP)
    
    DEFINE QLOCAL(QM3.XMITQ) USAGE(XMITQ)
    
    DEFINE QREMOTE (QM3) RNAME('') RQMNAME(QM3) XMITQ(QM3.XMITQ)
    
    DEFINE CHANNEL('QM1.TO.QM3') CHLTYPE(SDR) CONNAME('localhost(8888)') XMITQ(QM3.XMITQ) TRPTYPE(TCP)
    
    DEFINE CHANNEL('QM3.TO.QM1') CHLTYPE(RCVR) TRPTYPE(TCP)
  4. Start the appropriate listeners on the queue managers:
    runmqlsr -m QM1 -t TCP -p 9999 &
    runmqlsr -m QM2 -t TCP -p 7777 &
    runmqlsr -m QM3 -t TCP -p 8888 &
  5. Start the following channels:
    1. On QM1:
      START CHANNEL('QM1.TO.QM2')
      
      START CHANNEL('QM1.TO.QM3')
    2. On QM2:
      START CHANNEL('QM2.TO.QM1')
      
    3. On QM3:
      START CHANNEL('QM3.TO.QM1')
      
  6. Check that all the channels have started:
    DISPLAY CHSTATUS('QM1.TO.QM2')
    
    DISPLAY CHSTATUS('QM1.TO.QM3')
    
    DISPLAY CHSTATUS('QM2.TO.QM1')
    
    DISPLAY CHSTATUS('QM3.TO.QM1')

Scenario 1 part 3: Connect queue managers and define a topic

About this task

Connect the child queue managers QM2 and QM3 to the parent queue manager QM1.

Procedure

  1. On QM2 and QM3, set the parent queue manager to QM1:
    ALTER QMGR PARENT (QM1)
  2. Run the following command on all queue managers to check that the child queue managers are connected to the parent queue manager:
    DISPLAY PUBSUB TYPE(ALL)
  3. Define a topic object:
    define topic(FOOTBALL) TOPICSTR('Sport/Soccer')

Scenario 1 part 4: Publish and subscribe the topic

About this task

Use the amqspub.exe and amqssub.exe applications to publish and subscribe the topic.

Procedure

  1. Run this command in the first command window:
    amqspub Sport/Soccer QM2
  2. Run this command in the second command window:
    amqssub Sport/Soccer QM1
  3. Run this command in the third command window:
    amqssub Sport/Soccer QM3

Results

The amqssub.exe applications in the second and third command windows receive the messages published in the first command window.