Search code examples
pythonibm-mqpymqi

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


I amd trying put a string message in MQ using pymqi, the code is as follows;

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')

When I run this code, it doesn't throw any error. Hence, I get the feeling that the message has been put successfully on the required Queue.

However, I am expecting to see a record in one of my application screen after I send the above message to the Queue, and this is not happening.

If I put the same message through AppWatch (web interface), it works and I see the expected record on the application UI too.

On the AppWatch (web interface), when I do the 'Put Message', I mention the message type as : "String Format (MQFMT_STRING)".

How can I specify in my code that the message format is 'MQFMT_STRING'?

Appreciate your help on this.


Solution

  • According to the PyMQI Docs this is the definition of the put call:

    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.

    So in order to set the format you need to supply an MQMD Message Descriptor, the mDesc parameter on the put call.

    I haven't tried this out myself, but your code should look something like:

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