pythonibm-mqpymqi

How to connect to local MQseries queue using Python?


I am new to mqseries and I started with IBM WebSphere MQ curses. There are examples with MQ_APPLE and MQ_ORANGE queue managers. I have no problem with sending messages to local or remote queue with MQ Explorer, but I wanted to send such message from code: Python or Java. I tried Python pymqi library with code like this:

import pymqi

qmgr = pymqi.QueueManager(None)
qmgr.connect('QM_APPLE')

putq = pymqi.Queue(qmgr, 'Q1')
putq.put('Hello from Python!')

but I receive error:

Traceback (most recent call last):
    File "mq_put.py", line 4, in <module>
        qmgr.connect('QM_APPLE')
    File "c:\Python26\lib\site-packages\pymqi.py", line 758, in connect
        raise MQMIError(rv[1], rv[2])
pymqi.MQMIError: MQI Error. Comp: 2, Reason 2540: FAILED: MQRC_UNKNOWN_CHANNEL_NAME

There is QM_APPLE queue manager with Q1 local queue.

What is wrong with my code?


Solution

  • Based on the error it appears that you are attempting to connect to a remote queue manager, but you are using the local queue manager bindings method to connect. I say this because the error is stating that the mqi client doesn't know which channel to connect to. Can you please clarify if you are using a local queue manager or a remote queue manager? I have pasted the code below to connect to a remote queue manager using a channel.

    import pymqi
    
    queue_manager = "QUEUE_MANAGER_NAME"
    channel = "SVRCONN.1"
    host = "host.domain.com"
    port = "1434"
    conn_info = "%s(%s)" % (host, port)
    
    qmgr = pymqi.QueueManager(None)
    qmgr.connectTCPClient(queue_manager, pymqi.cd(), channel, conn_info)