IBM统计数据订阅主题始终返回原因2033:失败:MQRC\u NO\u MSG\u AVAILABLE

2024-09-29 17:18:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将一些旧的java代码移植到python

我正在使用pymqi连接到队列管理器,并使用主题字符串查询所有messageflow统计主题:$SYS/Broker/+/StatisticsAccounting/Archive/#

使用现有java程序时,从主题中读取消息时不会出现问题。 当使用新的python代码时,它能够毫无问题地连接和查询主题,但总是给出消息

Reason 2033: FAILED: MQRC_NO_MSG_AVAILABLE

代理每10分钟为每个消息流发布一次Stats消息,我让新代码运行了30多分钟,从未收到消息

我也试过设置

get_opts['WaitInterval'] = pymqi.CMQC.MQWI_UNLIMITED 

坐上20分钟,而不是使用循环,但没有运气

是否有任何IIB服务器配置可能会影响我能够看到的消息,或者是否有其他选项我应该在客户端中使用

import pymqi

queue_manager = 'MYQM'
channel = 'MYAPP.SVRCONN'
host = 'MYHOST'
port = 'MYPORT'
topic_string = '$SYS/Broker/+/StatisticsAccounting/Archive/#'
conn_info = '%s(%s)' % (host, port)
user = ""
password = ""

qmgr = pymqi.QueueManager(None)
qmgr.connect_tcp_client(queue_manager, pymqi.CD(), channel, conn_info, user, password)
sub_desc = pymqi.SD()
sub_desc['Options'] = pymqi.CMQC.MQSO_CREATE + pymqi.CMQC.MQSO_RESUME + pymqi.CMQC.MQSO_MANAGED
sub_desc.set_vs('SubName', 'apptest')
sub_desc.set_vs('ObjectString', topic_string)
sub = pymqi.Subscription(qmgr)
sub.sub(sub_desc=sub_desc)
get_opts = pymqi.GMO(Options=pymqi.CMQC.MQGMO_WAIT)
get_opts['WaitInterval'] = 10000

md = pymqi.md()
keep_running = True
while keep_running:
    try:
        # Reset the MsgId, CorrelId & GroupId so that we can reuse
        # the same 'md' object again.
        md.MsgId = pymqi.CMQC.MQMI_NONE
        md.CorrelId = pymqi.CMQC.MQCI_NONE
        md.GroupId = pymqi.CMQC.MQGI_NONE

        message = sub.get(None, md, get_opts)
        print('Have message from Queue')
        print(message)

    except pymqi.MQMIError as e:
        if e.comp == pymqi.CMQC.MQCC_FAILED and e.reason == pymqi.CMQC.MQRC_NO_MSG_AVAILABLE:
            print("no message?")
            print(e)
            pass
        else:
            # Some other error condition.
            raise

    except (UnicodeDecodeError, ValueError)  as e:
        print('Message is not valid json')
        print(e)
        print(message)
        continue

    except KeyboardInterrupt:
        print('Have received a keyboard interrupt')
        keep_running = False


sub.close(sub_close_options=0,close_sub_queue=True)
qmgr.disconnect()



Tags: 消息message主题getqueuemdrunningdesc

热门问题