Use MQSeriesTag(s): WinAPI/Registry WinAPI/Registry


  • You need the MQSeries ActiveX client installed on the workstation, you can get it freely from the IBM Web site.
  • An environment system variable (MQSERVER) must be defined.

    The format is MQSERVER = NAME.OF.CONNECTION/PRTOCOL/NAME.OF.SERVER(PORT).

    ex : MQSERVER = REMOTE.SVRCONN/TCP/MQSNT.SVR1.LOCAL(1414)

    Powerscript exemple which write a message then read it back.

    OLEObject MQS, QM, Q, ME, ML, PO, GO
    String ls_mqmgr, ls_s
    
    MQS = CREATE OLEObject   // MQSeries Session
    QM = CREATE OLEObject    // QueueManager
    Q = CREATE OLEObject     // Queue
    MW = CREATE OLEObject    // Message Written
    MR = CREATE OLEObject    // Message Read
    PO = CREATE OLEOBject    // Put options
    GO = CREATE OLEOBject    // Get options
    
    MQS.ConnectToNewObject("MQAX200.MqSession") // see note 1
    
    ls_mqmgr = "MQS.CORP.DEPT.DEV"                 // see note 2
    QM = MQS.AccessQueueManager(ls_mqmgr)
    Q = QM.AccessQueue("CORP.DEPT.SYST.STAGE.QNP1",1 + 16)  // see note 3
    // WRITE
    MW = MQS.AccessMessage
    MW.MessageData = "HELLO WORLD " + string(cpu())
    PO = MQS.AccessPutMessageOptions()
    Q.Put( MW,  PO)
    // READ
    MR = MQS.AccessMessage()
    MR.MessageIdHex = MR.MessageIdHex    // see note 4
    GO = MQS.AccessGetMessageOptions()
    Q.Get( MR,  GO)
    ls_s = MR.ReadString(MR.MessageLength)
    MessageBox("MQSeries", ls_s)
    
    Q.close()
    QM.disconnect()
    
    NOTE:
    1. Connection to the ActiveX
    2. The Queue Manager
    3. The Queue Name , see the constant defintion below, here the Queue is INPUT and OUTPUT
    4. Just to make sure that we are reading the good message.

    The possible constants are :

    Message TYPE
    
    Global Const MQMT_SYSTEM_FIRST = 1
    Global Const MQMT_REQUEST = 1
    Global Const MQMT_REPLY = 2
    Global Const MQMT_DATAGRAM = 8
    Global Const MQMT_REPORT = 4
    Global Const MQMT_SYSTEM_LAST = 65535
    Global Const MQMT_APPL_FIRST = 65536
    Global Const MQMT_APPL_LAST = 999999999
    
    Open Options
    
    Global Const MQOO_INPUT_AS_Q_DEF = 1
    Global Const MQOO_INPUT_SHARED = 2
    Global Const MQOO_INPUT_EXCLUSIVE = 4
    Global Const MQOO_BROWSE = 8
    Global Const MQOO_OUTPUT = 16
    Global Const MQOO_INQUIRE = 32
    Global Const MQOO_SET = 64
    Global Const MQOO_SAVE_ALL_CONTEXT = 128
    Global Const MQOO_PASS_IDENTITY_CONTEXT = 256
    Global Const MQOO_PASS_ALL_CONTEXT = 512
    Global Const MQOO_SET_IDENTITY_CONTEXT = 1024
    Global Const MQOO_SET_ALL_CONTEXT = 2048
    Global Const MQOO_ALTERNATE_USER_AUTHORITY = 4096
    Global Const MQOO_FAIL_IF_QUIESCING = 8192
    
    
    Put Message Options
    
    Global Const MQPMO_SYNCPOINT = 2
    Global Const MQPMO_NO_SYNCPOINT = 4
    Global Const MQPMO_NEW_MSG_ID = 64
    Global Const MQPMO_NEW_CORREL_ID = 128
    Global Const MQPMO_LOGICAL_ORDER = 32768
    Global Const MQPMO_NO_CONTEXT = 16384
    Global Const MQPMO_DEFAULT_CONTEXT = 32
    Global Const MQPMO_PASS_IDENTITY_CONTEXT = 256
    Global Const MQPMO_PASS_ALL_CONTEXT = 512
    Global Const MQPMO_SET_IDENTITY_CONTEXT = 1024
    Global Const MQPMO_SET_ALL_CONTEXT = 2048
    Global Const MQPMO_ALTERNATE_USER_AUTHORITY = 4096
    Global Const MQPMO_FAIL_IF_QUIESCING = 8192
    Global Const MQPMO_NONE = 0
    
    Get Message Options
    
    Global Const MQGMO_WAIT = 1
    Global Const MQGMO_NO_WAIT = 0
    Global Const MQGMO_SYNCPOINT = 2
    Global Const MQGMO_SYNCPOINT_IF_PERSISTENT = 4096
    Global Const MQGMO_NO_SYNCPOINT = 4
    Global Const MQGMO_MARK_SKIP_BACKOUT = 128
    Global Const MQGMO_BROWSE_FIRST = 16
    Global Const MQGMO_BROWSE_NEXT = 32
    Global Const MQGMO_BROWSE_MSG_UNDER_CURSOR = 2048
    Global Const MQGMO_MSG_UNDER_CURSOR = 256
    Global Const MQGMO_LOCK = 512
    Global Const MQGMO_UNLOCK = 1024
    Global Const MQGMO_ACCEPT_TRUNCATED_MSG = 64
    Global Const MQGMO_SET_SIGNAL = 8
    Global Const MQGMO_FAIL_IF_QUIESCING = 8192
    Global Const MQGMO_CONVERT = 16384
    Global Const MQGMO_LOGICAL_ORDER = 32768
    Global Const MQGMO_COMPLETE_MSG = 65536
    Global Const MQGMO_ALL_MSGS_AVAILABLE = 131072
    Global Const MQGMO_ALL_SEGMENTS_AVAILABLE = 262144
    Global Const MQGMO_NONE = 0
    
    Powerscript example reading from a Queue but with a check if the Queue is empty.
    OLEObject MQS, QM, Q, ML, GO
    String ls_mqmgr, ls_s
    
    MQS = CREATE OLEObject
    QM = CREATE OLEObject
    Q = CREATE OLEObject
    MR = CREATE OLEObject
    GO = CREATE OLEOBject
    
    MQS.ConnectToNewObject("MQAX200.MqSession")
    
    ls_mqmgr = "MQS.CORP.DEPT.DEV"
    QM = MQS.AccessQueueManager(ls_mqmgr)
    Q = QM.AccessQueue("CORP.DEPT.SYST.STAGE.QNP1",1 + 32)  // INPUT & INQUIRE
    
    IF Q.CurrentDepth = 0 THEN
        MessageBox("", "The Queue is empty")
    ELSE
        ls_s = string(Q.CurrentDepth)
        MessageBox("", "The Queue has " + ls_s + " element(s)")
    
        ML = MQS.AccessMessage()
        MR.MessageType = 77777   // our known message type
        GO = MQS.AccessGetMessageOptions()
        GO.Options = GO.OPtions + 4  // GOO_NO_SYNCPOINT
        Q.Get( MR,  GO )
    
        ls_s = MR.ReadString(ML.MessageLength)
        MessageBox("MQSeries", ls_s)
    END IF
    
    Q.close()
    QM.disconnect()
    
    

    The next example is two applications talking each other.

    The first writes a message into a Queue with a known type. The second application reads at regular interval the Queue for available messages and prints them into scrolling listbox.

    First application :

    [button script]
    OLEObject MQS, QM, Q, MW, PO
    String ls_mqmgr, ls_s
    
    MQS = CREATE OLEObject
    QM = CREATE OLEObject
    Q = CREATE OLEObject
    MW = CREATE OLEObject
    PO = CREATE OLEOBject
    
    
    MQS.ConnectToNewObject("MQAX200.MqSession")
    
    ls_mqmgr = "MQS.CORP.DEPT.DEV"
    QM = MQS.AccessQueueManager(ls_mqmgr)
    Q = QM.AccessQueue("CORP.DEPT.SYST.STAGE.QNP1",16)  // OUTPUT
    
    MW = MQS.AccessMessage
    MW.MessageData = "HELLO WORLD "  + string(cpu())
    MW.MessageType = 77778
    MW.Format = "MQSTR"
    PO = MQS.AccessPutMessageOptions()
    Q.Put( MW,  PO)
    Q.close()
    QM.disconnect()
    

    Application 2

    [window instance variable]
    OLEObject iMQS, iQM, iQ, iMR, iGO
    String is_mqmgr, is_s
    
    
    [open window event]
    iMQS = CREATE OLEObject
    iQM = CREATE OLEObject
    iQ = CREATE OLEObject
    iMR = CREATE OLEObject
    iGO = CREATE OLEOBject
    
    iMQS.ConnectToNewObject("MQAX200.MqSession")
    
    is_mqmgr = "MQS.CORP.DEPT.DEV"
    iQM = iMQS.AccessQueueManager(is_mqmgr)
    timer(1)
    
    [close window event]
    // QUEUE MANAGER DISCONNECT
    // iQM.disconnect()
    
    
    [timer window event]
    // write into a listbox (w=1563 h=572 not sorted vscrollbar)
    integer cpt = 0
    
    iQ = iQM.AccessQueue("CORP.DEPT.SYST.STAGE.QNP1",1 + 32)  // INPUT,INQUIRE
    
    IF iQ.CurrentDepth = 0 THEN
        cpt = lb_1.additem("The Queue is empty")
    ELSE
        iMR = iMQS.AccessMessage()
        iMR.MessageType = 77778
        iGO = iMQS.AccessGetMessageOptions()
        iGO.Options = iGO.OPtions + 4  // GOO_NO_SYNCPOINT
        iQ.Get( iMR,  iGO )
    
        is_s = iMR.ReadString(iML.MessageLength)
        cpt = lb_1.additem(is_s)
    END IF
    
    IF cpt > 8 THEN
        lb_1.SetTop(cpt - 8 + 1)
    END IF
    
    // QUEUE close
    // Q.close()
    

    blog comments powered by Disqus