Python pymqi : 如何指定放入队列的消息格式

Python pymqi : How to specify the message format for putting to a queue

我正在尝试使用pymqi将字符串消息放入MQ中,代码如下;

import xml.dom.minidom as minidom
import pymqi

class PutMQ:
    def put_mq(args1):
        doc = minidom.parse(args1)                       
        queue_manager = "NameQueueManager"
        channel = "ChannelName"
        host = "HostName"
        port = "PortNumber"
        conn_info = "%s(%s)" % (host, port)

        qmgr = pymqi.QueueManager(None)

        qmgr.connectTCPClient(queue_manager, pymqi.cd(), channel, conn_info)

        putq = pymqi.Queue(qmgr, 'QueueName')


        putq.put(doc.toprettyxml())

        putq.close()
        qmgr.disconnect()
    put_mq('C://MQ//myMessage.xml')

当我运行这段代码时,它不会抛出任何错误。因此,我感觉消息已成功放入所需的队列中。

但是,我希望在将上述消息发送到队列后在我的应用程序屏幕之一中看到一条记录,但这并没有发生。

如果我通过 AppWatch(Web 界面)发送相同的消息,它会起作用,我也会在应用程序 UI 上看到预期的记录。

在 AppWatch(网络界面)上,当我执行 'Put Message' 时,我提到消息类型为:"String Format (MQFMT_STRING)"。

如何在我的代码中指定消息格式为 'MQFMT_STRING'?

感谢您对此的帮助。

根据 PyMQI Docs 这是 put 调用的定义:

put(msg[, mDesc, putOpts])

Put the string buffer ‘msg’ on the queue. If the queue is not already open, it is opened now with the option ‘MQOO_OUTPUT’.

mDesc is the pymqi.md() MQMD Message Descriptor for the message. If it is not passed, or is None, then a default md() object is used.

putOpts is the pymqi.pmo() MQPMO Put Message Options structure for the put call. If it is not passed, or is None, then a default pmo() object is used.

If mDesc and/or putOpts arguments were supplied, they may be updated by the put operation.

因此,为了设置格式,您需要提供 MQMD 消息描述符,put 调用的 mDesc 参数。

我自己还没有尝试过,但是您的代码应该类似于:

md = pymqi.MD()
md.Format = CMQC.MQFMT_STRING
putq.put(doc.toprettyxml(), md, None)