-
we need install mqsdk and mqclient before install pymqi
sudo apt install ./ibmmq-sdk_9.1.5.0_amd64.deb
sudo apt install ./ibmmq-client_9.1.5.0_amd64.deb
pip install pymqi
export LD_LIBRARY_PATH=/opt/mqm/lib64:$LD_LIBRARY_PATH -
create qmgr, channel and LISTENER on MQ server
https://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ins.doc/q009310_.htm
https://dsuch.github.io/pymqi/examples.html
create a user ID on the server that is not in the mqm group.
useradd testid
passwd testid
su – mqmmqm@ubunu2004:~$ crtmqm QUEUE.MANAGER.1 mqm@ubunu2004:~$ strmqm QUEUE.MANAGER.1 mqm@ubunu2004:~$ runmqsc QUEUE.MANAGER.1 5724-H72 (C) Copyright IBM Corp. 1994, 2020. Starting MQSC for queue manager QUEUE.MANAGER.1. AMQ8521I: Command completion and history unavailable. DEFINE QLOCAL (QUEUE1) 1 : DEFINE QLOCAL (QUEUE1) AMQ8006I: IBM MQ queue created. SET AUTHREC PROFILE(QUEUE1) OBJTYPE(QUEUE) PRINCIPAL('testid') AUTHADD(PUT,GET) 2 : SET AUTHREC PROFILE(QUEUE1) OBJTYPE(QUEUE) PRINCIPAL('testid') AUTHADD(PUT,GET) AMQ8862I: IBM MQ authority record set. SET AUTHREC OBJTYPE(QMGR) PRINCIPAL('testid') AUTHADD(CONNECT) 3 : SET AUTHREC OBJTYPE(QMGR) PRINCIPAL('testid') AUTHADD(CONNECT) AMQ8862I: IBM MQ authority record set. DEFINE CHANNEL (CHANNEL1) CHLTYPE (SVRCONN) TRPTYPE (TCP) 4 : DEFINE CHANNEL (CHANNEL1) CHLTYPE (SVRCONN) TRPTYPE (TCP) AMQ8014I: IBM MQ channel created. SET CHLAUTH(CHANNEL1) TYPE(ADDRESSMAP) ADDRESS('192.168.0.43') MCAUSER('testid') 5 : SET CHLAUTH(CHANNEL1) TYPE(ADDRESSMAP) ADDRESS('192.168.0.43') MCAUSER('testid') AMQ8877I: IBM MQ channel authentication record set. DEFINE LISTENER (LISTENER1) TRPTYPE (TCP) CONTROL (QMGR) PORT (1415) 6 : DEFINE LISTENER (LISTENER1) TRPTYPE (TCP) CONTROL (QMGR) PORT (1415) AMQ8626I: IBM MQ listener created. START LISTENER (LISTENER1) 7 : START LISTENER (LISTENER1) AMQ8021I: Request to start IBM MQ listener accepted.
-
test_mq.py
import pymqi queue_manager = "QUEUE.MANAGER.1" channel = "CHANNEL1" host = "192.168.0.43" port = "1415" queue_name = 'QUEUE1' message = 'Hello from Python!' conn_info = "%s(%s)" % (host, port) user = 'testid' password = 'password' qmgr = pymqi.connect(queue_manager, channel, conn_info, user, password) queue = pymqi.Queue(qmgr, queue_name) queue.put(message) queue.close() qmgr.disconnect()
(base) ubuntu@ubunu2004:~$ python test_mq.py
then you can verify it with amqsget:mqm@ubunu2004:/opt/mqm/samp/bin$ ./amqsget QUEUE1 QUEUE.MANAGER.1 Sample AMQSGET0 start message <Hello from Python!> no more messages Sample AMQSGET0 end