开发者

How to connect to local MQseries queue using Python?

开发者 https://www.devze.com 2022-12-24 06:09 出处:网络
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

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_UNKNOW开发者_如何学编程N_CHANNEL_NAME

There is QM_APPLE queue manager with Q1 local queue.

What is wrong with my code?


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)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消