PyMQI是一个即将投产的IBM消息队列中间件扩展程序。它使得python通过之间调用MQI来连接队列,在其中获取和放入消息。
环境:
# pymqi-1.7.2.post1 windows 7 64 ,Python2.7.15 ibmmq 7.0 client
代码:
recv_mq = {
"name": "MQ_A_RECV_1",
"ip": "180.2.34.55",
"port": 1424,
"username": "mqm",
"password": "mqm",
"recv_queue_manager": "QMUHVP1",
"recv_channel": "HVP1.SVRC",
"recv_queue": "MSGTOPMTS1_1",
}
try:
qmgr = pymqi.connect(recv_mq["recv_queue_manager"], recv_mq["recv_channel"], recv_mq["ip"] + "(" + str(recv_mq["port"]) + ")", recv_mq["username"], recv_mq["password"])
queue = pymqi.Queue(qmgr, recv_mq["recv_queue"])
except Exception as e:
log.error(recv_mq["ip"] + "(" + str(recv_mq["port"]) + ") " + recv_mq["recv_queue_manager"] + " " + recv_mq["name"] + " 连接失败: " + str(e))
send_lock.release()
return
log.debug(recv_mq["ip"] + "(" + str(recv_mq["port"]) + ") " + recv_mq["recv_queue_manager"] + " " + recv_mq["recv_queue"] + ":连接" + recv_mq["name"] + "成功")
count = queue.inquire(pymqi.CMQC.MQIA_CURRENT_Q_DEPTH)
queue.close()
log.debug(recv_mq["ip"] + "(" + str(recv_mq["port"]) + ") " + recv_mq["recv_queue_manager"] + " " + recv_mq["recv_queue"] + "当前队列深度: " + str(count))
if count > 0:
queue = pymqi.Queue(qmgr, recv_mq["recv_queue"])
msg = queue.get()
log.debug("[" + str(tag_id) + "] " + " 从 " + recv_mq["name"] + "拿取请求:" + str(msg))
queue.close()
qmgr.disconnect()