(WMQ) PCF commands Intro

The purpose of WebSphere® MQ programmable command format (PCF) commands is to allow administration tasks to be programmed into an administration program. In this way, from a program we can manipulate queue manager objects (queues, process definitions, namelists, channels, client connection channels, listeners, services, and authentication information objects), and even manipulate the queue managers themselves.
PCF commands cover the same range of functions provided by MQSC commands. We can write a program to issue PCF commands to any queue manager.
Each PCF command is a data structure that is embedded in the application data part of a WebSphere MQ message. Each command is sent to the target queue manager using the MQI function MQPUT in the same way as any other message. Providing the command server is running on the queue manager receiving the message, the command server interprets it as a command message and runs the command. To get the replies, the application issues an MQGET call and the reply data is returned in another data structure. The application can then process the reply and act accordingly.
Sample Java code for creating local queues :
Imports are :
import com.ibm.mq.MQC;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.CMQC;
import com.ibm.mq.constants.CMQCFC;
import com.ibm.mq.headers.pcf.MQCFIN;
import com.ibm.mq.headers.pcf.MQCFST;
import com.ibm.mq.headers.pcf.PCFAgent;
import com.ibm.mq.headers.pcf.PCFParameter;
import com.ibm.mq.pcf.MQCFH;
import com.ibm.mq.pcf.MQCFSL;

private static void createQueues(String[] queues)throws Exception {
MQQueueManager qMgr;
qMgr = new MQQueueManager("QM");
PCFAgent   agent = new PCFAgent (qMgr);
MQMessage []   responses;
int queueCounter =0;
for(;queueCounter<queues.length;queueCounter++)
{
  PCFParameter [] parameters = 
    {
      new MQCFST (CMQC.MQCA_Q_NAME, queues[queueCounter]),
      new MQCFIN (CMQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL)
    };
  MQCFH     cfh;
  responses = agent.send (CMQCFC.MQCMD_CREATE_Q, parameters);
  cfh = new MQCFH (responses [0]);
  if(cfh.reason==4001)
  System.out.println("Queue Name : "+queues[queueCounter] +" is already present");
  else if(cfh.reason==0)
  System.out.println("Queue Name : "+queues[queueCounter] +" is created");
 }
}

Sample Java code for displaying all the local queues in queue manager:
private static void getQueueNames() throws Exception {
MQQueueManager qMgr;
qMgr = new MQQueueManager("QM");
PCFAgent   agent = new PCFAgent (qMgr);
MQMessage []   responses;
PCFParameter [] parameters = 
{
new MQCFST (CMQC.MQCA_Q_NAME, "*"), 
new MQCFIN (CMQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL)
};
MQCFH cfh;
MQCFSL cfsl;
responses = agent.send (CMQCFC.MQCMD_INQUIRE_Q_NAMES, parameters);
cfh = new MQCFH (responses [0]);
if (cfh.reason == 0)
{
  cfsl = new MQCFSL (responses [0]);
  for (int i = 0; i < cfsl.strings.length; i++)
  {
    System.out.println ("Queue: " + cfsl.strings [i]);
  }
}
}


Jars required :

com.ibm.mq.headers.jar
com.ibm.mq.jar
com.ibm.mq.jmqi.jar
com.ibm.mq.pcf.jar


8 comments:

  1. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this.
    Are you aware of any other websites on this

    IBM-MQ WEBSPHERE Online training

    .

    ReplyDelete
  2. Hi Harish,
    Thank you for the useful information.
    I am facing a issue, when I try to import 'com.ibm.mq.headers.pcf.PCFAgent' an error shows up that PCFAgent class is not found. I tried downloading jars but no luck. None of them have got PCFAgent class.
    Could you please help me.
    Thank you in advance

    ReplyDelete
  3. Yeah , it is a good post and valuable.
    One thing I like to add here rather to download the jars(given 4 jar Names) take it from the MQ installation lib directory.
    It will help you jar version dependency problem, which I was experienced.

    ReplyDelete
  4. Nice site for ORACLE, Good Information provided my Mate on OBIEE Online Training

    ReplyDelete
  5. I have read your blog its very attractive and impressive
    Websphere mq Training in Bangalore

    ReplyDelete