Home > Software > WebSphere MQ Administration with Python. Part I – introducing PCFExecute

WebSphere MQ Administration with Python. Part I – introducing PCFExecute

March 10th, 2011

Hi and welcome to the first installment in the WebSphere MQ Administration with Python series. The goal is to introduce readers to the topic of performing admin tasks with Python and encourage those who still waver over whether to migrate all those Visual Basic or Java tools to actually start using Python, a modern, fast and cross-platform programming language.

The Python interface to MQ is called PyMQI and among many goodies it provides there’s also a very useful pymqi.PCFExecute class. PCF is, as you surely remember, a short for Programmable Command Formats, which basically means it’s an API for writing programs that are meant to automate tasks MQ admins usually do.

How does it work in Python? Well, you just need to open the appropriate MQ manual and pick any PCF command, say an MQCMD_PING_Q_MGR. The name you’ve chosen is always available as an attribute of the PCFExecute class instances, like below:

import pymqi
 
queue_manager = "QM01"
channel = "SVRCONN.1"
host = "192.168.1.139"
port = "1434"
conn_info = "%s(%s)" % (host, port)
 
qmgr = pymqi.QueueManager(None)
qmgr.connectTCPClient(queue_manager, pymqi.cd(), channel, conn_info)
pcf = pymqi.PCFExecute(qmgr)
 
# Woohoo, we've just executed our first PCF command!
pcf.MQCMD_PING_Q_MGR()
 
qmgr.disconnect()

So you just need to connect to a queue manager, create an instance of the pymqi.PCFExecute class and then you can directly invoke anything that’s listed in MQ manuals.

OK, that was easy as pinging a queue manager doesn’t require any parameters nor does it return anything. How about something less trivial, like creating a new queue with MQCMD_CREATE_Q?

import CMQC
import pymqi
 
queue_manager = "QM01"
channel = "SVRCONN.1"
host = "192.168.1.139"
port = "1434"
conn_info = "%s(%s)" % (host, port)
 
qmgr = pymqi.QueueManager(None)
qmgr.connectTCPClient(queue_manager, pymqi.cd(), channel, conn_info)
pcf = pymqi.PCFExecute(qmgr)
 
queue_name = "PYMQI.1"
queue_type = CMQC.MQQT_LOCAL
 
args = {CMQC.MQCA_Q_NAME: queue_name, CMQC.MQIA_Q_TYPE: queue_type}
 
pcf.MQCMD_CREATE_Q(args)
 
qmgr.disconnect()

MQCMD_CREATE_Q obviously needs some arguments and these are passed in wrapped in a dictionary whose keys are the same as the manual says there should be. For instance, it says that MQCA_Q_NAME and MQIA_Q_TYPE are required identifiers so I knew I could use the PyMQI’s CMQC module for looking them up. Likewise, the manual lists all the supported queue types and they also can be found in CMQC and that’s how I knew I could use CMQC.MQQT_LOCAL for the queue type. So to recap, the arguments – required and optional – are explained in the MQ documentation and you need to use PyMQI constants to form a dictionary and pass it in to the PCF command of your choice. What other modules are there in addition to CMQC? Well, there’s also CMQXC and CMQCFC and PyMQI 1.2 will introduce CMQZC – they all may be used for constructing the arguments to PCF calls.

So here it is, an introduction to PCFExecute. I plan on writing more about manipulating MQ objects, queues, channels, queue managers, aliases and so on and if you’d like to have anything covered you just need to drop me an e-mail. Thanks!

@fourthrealm

Share
  1. March 12th, 2011 at 05:54 | #1

    What a useful post, very useful indeed!

    What is interesting is the amount of code that it saved in doing this in Python VS doing it in C / C++ ;-)

    Looking forward to you next post ;-)

    Lynton

  2. Andrew Robert
    March 12th, 2011 at 13:25 | #2

    A very good start! Thanks. One thing I would suggest is addressing installation of PyMQI.

  3. Peter
    March 25th, 2011 at 14:26 | #3

    Hi, what I would like is an easy to use cross-platform, interpreted MQI language – look this is it – so now I want ready to run versions already compiled (the whole point is that I don’t have or understand “C” – the open source community seem to think everyone can use compilers and builders – I have no experience doing this, nor do I want to!).

    I see the ready to use Windows binaries – what about AIX and Linux64 and/or Linux32? Downloads of these would make it accessible to the very people it is aimed at – thanks…

  4. March 25th, 2011 at 14:39 | #4

    @Peter,

    as far as Linux goes, installing PyMQI is usually a matter of doing “sudo pip install pymqi” – that will download the latest version from PyPI and automatically compile it, that’s how packages for Python get usually installed. Or you can download the .tar.gz and invoke pip locally. Or you can unpack the archive and manually issue “python setup.py install”. I can’t speak for the whole open source community but I certainly am not very happy with compiling stuff manually, hence I’m using Python :-) I understand it may be something new to you (I mean compiling Python extensions) but I just had to assume some knowledge – if you think I went too far, can you please help me and suggest how I could improve the docs? Many thanks!

    AIX – well, I have no access to an AIX box. I’ve already asked various people and no one was able to contribute access to such a system. If you can, then I’ll be *very* happy to learn how to create AIX binaries and provide one for PyMQI.

Comments are closed.