Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 754
Michał Niklas Avatar asked Mar 29 '10 08:03

Michał Niklas


2 Answers

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)
like image 101
gregwhitaker Avatar answered Sep 19 '22 12:09

gregwhitaker


Your post mentions you'd like this to run in Python or Java. Python I can't help with but the previous responder did, so cool. As far as Java, maybe I can point you in the right direction. IBM supports both Java and JMS and provides a number of sample programs of each. By default, these are installed at:

C:\Program Files\IBM\WebSphere MQ\tools\wmqjava

C:\Program Files\IBM\WebSphere MQ\tools\jms

I also offer up my own sample code here: http://www.ibm.com/developerworks/websphere/techjournal/0610_woolf/0610_woolf.html

The documentation for the IBM's implementation of the Java and JMS WMQ API is here: http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzaw.doc/uj10120_.htm

The docs I found on the Python module appear to indicate that it must be linked to the Client or Server WMQ libraries and your error seems to indicate that you have the client bindings linked. If that's the case, you must provide the connection info as the previous posted pointed out. The Java and JMS code support either connection type so there's no linking to be done but you still must supply the proper connection details. In particular, please read the chapter on Connection Differences: http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzaw.doc/ja11010_.htm

-- T.Rob

like image 20
T.Rob Avatar answered Sep 19 '22 12:09

T.Rob