如何使用Python连接到本地MQseries队列?

发布于 2024-08-26 18:24:15 字数 791 浏览 7 评论 0原文

我是 mqseries 的新手,我从 IBM WebSphere MQcurses 开始。有 MQ_APPLEMQ_ORANGE 队列管理器的示例。我使用 MQ Explorer 向本地或远程队列发送消息没有问题,但我想从代码发送此类消息:Python 或 Java。我尝试使用如下代码的 Python pymqi 库:

import pymqi

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

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

但收到错误:

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

存在带有 Q1 本地队列的 QM_APPLE 队列管理器。

我的代码有什么问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见你 2024-09-02 18:24:15

根据该错误,您似乎正在尝试连接到远程队列管理器,但正在使用本地队列管理器绑定方法进行连接。我这样说是因为错误表明 mqi 客户端不知道要连接到哪个通道。您能否澄清一下您使用的是本地队列管理器还是远程队列管理器?我已粘贴下面的代码以使用通道连接到远程队列管理器。

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)

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)
酒中人 2024-09-02 18:24:15

您的帖子提到您希望它在 Python 或 Java 中运行。 Python 我帮不上忙,但之前的回复者做到了,太酷了。就 Java 而言,也许我可以为您指明正确的方向。 IBM 支持 Java 和 JMS,并分别提供了许多示例程序。默认情况下,它们安装在:

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

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

我还在这里提供了我自己的示例代码:
http://www.ibm.com/developerworks/websphere/techjournal/ 0610_w​​oolf/0610_w​​oolf.html

IBM Java 和 JMS WMQ API 实现的文档位于此处:
http:// publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzaw.doc/uj10120_.htm

我在Python模块上找到的文档似乎表明它必须链接到客户端或服务器 WMQ 库,并且您的错误似乎表明您已链接客户端绑定。如果是这种情况,您必须按照上一篇文章指出的那样提供连接信息。 Java 和 JMS 代码支持任一连接类型,因此无需进行链接,但您仍然必须提供正确的连接详细信息。特别是,请阅读有关连接差异的章节:
http:// publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzaw.doc/ja11010_.htm

-- T.Rob

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文