pythonibm-mqpymqi

How Get a list of MQ queues pymqi?


You want to get a list of the queues for a specific queue manager. I seem to understand how to do this, but when I try, I get an error.

Traceback (most recent call last): File "D:/project/Work-Project/queue list.py", line 23, in response = pcf.MQCMD_INQUIRE_Q(args) File "C:\Users\ShevcovAA\AppData\Local\Programs\Python\Python37\lib\site-packages\pymqi_init_.py", line 2769, in call message = self._pcf.reply_queue.get(None, get_md, get_opts) File "C:\Users\ShevcovAA\AppData\Local\Programs\Python\Python37\lib\site-packages\pymqi_init.py", line 2021, in get raise MQMIError(rv[-2], rv[-1], message=rv[0], original_length=rv[-3]) pymqi.MQMIError: MQI Error. Comp: 2, Reason 2033: FAILED: MQRC_NO_MSG_AVAILABLE

My Code:

import logging
import re
import pymqi

logging.basicConfig(level=logging.INFO)

queue_manager = 'QM1'
channel = 'DEV.APP.SVRCONN'
host = '127.0.0.1'
port = '1414'
conn_info = '%s(%s)' % (host, port)

prefix = "*"
queue_type = pymqi.CMQC.MQQT_LOCAL

args = {pymqi.CMQC.MQCA_Q_NAME: prefix,
        pymqi.CMQC.MQIA_Q_TYPE: queue_type}

qmgr = pymqi.connect(queue_manager, channel, conn_info)
pcf = pymqi.PCFExecute(qmgr)

response = pcf.MQCMD_INQUIRE_Q(args)

for queue_info in response:
    queue_name = queue_info[pymqi.CMQC.MQCA_Q_NAME]
    if (re.match('^SYSTEM', queue_name) or re.match('^AMQ', queue_name) or re.match('^MQ', queue_name)):
        pass
    else:
        q = pymqi.Queue(qmgr, queue_name)
        print(queue_name.strip() + ':' + 'Queue  depth:', q.inquire(pymqi.CMQC.MQIA_CURRENT_Q_DEPTH))
        q.close()

qmgr.disconnect()

Solution

  • v1.12.0 pymqi uses different logic to get PCF response messages from the response queue.

    By default, a timeout of 5 seconds is used to wait for a response. As a result, if you have a lot of queues or your QM is under heavy load, this may not be enough.

    To fix this, you can increase this interval using the response_wait_interval parameter of the PCFExecute constructor.

    pcf = pymqi.PCFExecute(qmgr, response_wait_interval=30000) # 30 seconds
    

    v1.11.0 does not have this parameter and uses default interval of 30 seconds.

    And avoid querying each queue for depth, just query MQIA_CURRENT_Q_DEPTH attribute.

    In new notation, supported in v1.12+, it will be something like:

        attrs = []  # type: List[pymqi.MQOpts]
        attrs.append(pymqi.CFST(Parameter=pymqi.CMQC.MQCA_Q_NAME,
                                String=pymqi.ensure_bytes(prefix)))
        attrs.append(pymqi.CFIN(Parameter=pymqi.CMQC.MQIA_Q_TYPE,
                                Value=queue_type))
        attrs.append(pymqi.CFIL(Parameter=pymqi.CMQCFC.MQIACF_Q_ATTRS,
                                Values=[pymqi.CMQC.MQIA_CURRENT_Q_DEPTH]))
    
        object_filters = []
    #        object_filters.append(
    #            pymqi.CFIF(Parameter=pymqi.CMQC.MQIA_CURRENT_Q_DEPTH,
    #                       Operator=pymqi.CMQCFC.MQCFOP_GREATER,
    #                       FilterValue=0))
    
        response = pcf.MQCMD_INQUIRE_Q(attrs, object_filters)
    
        for queue_info in response:
            queue_name = queue_info[pymqi.CMQC.MQCA_Q_NAME]
            queue_depth = queue_info[pymqi.CMQC.MQIA_CURRENT_Q_DEPTH]
            print('{}: {} message(s)'.format(queue_name.strip().decode(), queue_depth))