我是python的新手。我试图连接到我的IBM MQ并通过Python代码在其中添加一些消息。
import pymqi
queue_manager = 'XXXXXX'
channel = 'XXXXX'
host = 'XXXXX'
port = 'XXXX'
conn_info = '%s(%s)' % (host, port)
qmgr = pymqi.connect(queue_manager, channel, conn_info)
file = open('E:\D Drive Back up\Scripts\Data1.csv','r')
y = file.readlines()
print y[1]
putQ = pymqi.Queue(qmgr, queue_manager)
putQ.put(y[1])
qmgr.disconnect()
我要输入的样本数据:
{1:F01COBADEFFGXXX3575743055}{2:I103BARCGB22GXXXU3003}{4:##:20:Forw092010004R1##:23B:CRED##:32A:181010EUR250000,00##:50F:/N101000004EUR##1/John Doe##2/Dankelmannstrasse 6##3/DE/Berlin##:59F:/N101000004EUR##1/Jane Doe##2/Wissmannstr 1##3/DE/Berlin##:71A:BEN##-}{5:{MAC:11111111}{CHK:6E470F24FDE6}}
我得到的输出是这样:
E:\D Drive Back up\Scripts>python MQ.py
{1:F01COBADEFFGXXX3575743055}{2:I103BARCGB22GXXXU3003}{4:##:20:Forw092010R1##:23B:CRED##:32A:181010EUR1000000,00##:50F:/N101000004EUR##1/John Doe##2/Dankelmannstrasse 6##3/DE/Berlin##:59F:/N101000004EUR##1/Jane Doe##2/Wissmannstr 1##3/DE/Berlin##:71A:BEN##-}{5:{MAC:11111111}{CHK:6E470F24FDE6}}
Traceback (most recent call last):
File "MQ.py", line 19, in
putQ.put(y[1])
File "C:\Users\aassharma\AppData\Local\Continuum\anaconda2\lib\site-packages\pymqi_init_.py", line 1727, in put
self._realOpen()
File "C:\Users\aassharma\AppData\Local\Continuum\anaconda2\lib\site-packages\pymqi_init.py", line 1632, in __realOpen
raise MQMIError(rv[-2], rv[-1])
pymqi.MQMIError: MQI Error. Comp: 2, Reason 2085: FAILED: MQRC_UNKNOWN_OBJECT_NAME
答案 0 :(得分:2)
将您的代码与-https://dsuch.github.io/pymqi/examples.html#how-to-put-the-message-on-a-queue
的pymqi put示例进行比较import pymqi
queue_manager = 'QM1'
channel = 'DEV.APP.SVRCONN'
host = '127.0.0.1'
port = '1414'
queue_name = 'TEST.1'
message = 'Hello from Python!'
conn_info = '%s(%s)' % (host, port)
qmgr = pymqi.connect(queue_manager, channel, conn_info)
queue = pymqi.Queue(qmgr, queue_name)
queue.put(message)
queue.close()
qmgr.disconnect()
正如Morag Hughson和JoshMc所指出的,区别是queue_name
。您不指定一个。
它应该类似于“ DEV.QUEUE.1”,并用作连接到队列的调用中的第二个参数-queue = pymqi.Queue(qmgr, queue_name)
。您传入了队列管理器,我想它将类似于“ QM1”,它不太可能是您的MQ服务器上的队列名称,以及为什么会收到错误MQRC_UNKNOWN_OBJECT_NAME
。