WebSphere Message Broker - how to send a PCF messa

2020-03-26 05:18发布

We need to issue some MQ commands from a MB flow. The way to go is to send a PCF command, but I dont know how to create it. Any pointers ? Sebastian.

标签: ibm-mq broker
1条回答
孤傲高冷的网名
2楼-- · 2020-03-26 06:11

To issue commands to an MQ Queue Manager via PCF messages you can look at the examples in /opt/mqm/samp/pcf/samples on *nix or where ever you have installed MQ. (On Windows try "C:\Program Files (x86)\IBM\WebSphere MQ\tools\pcf\samples").

To issue the commands 'from' broker you can use a Java compute node and use methods in the supplied Java package com.ibm.mq, for example sending a query to find out what queues are defined on a queue manager:

import com.ibm.mq.headers.pcf.PCFMessageAgent;
import com.ibm.mq.headers.pcf.PCFMessage;
import com.ibm.mq.constants.MQConstants;

try
{
    // local queue manager
    String queueManager = "QMGR_broker"; // local queue manager name 
    PCFMessageAgent agent = new PCFMessageAgent(queueManager);

    // remote queue manager
    String host = "localhost"; // host name of the queue manager machine
    int port = 1414; // default queue manager tcp listener port
    String channel = "SYSTEM.DEF.SVRCONN";//Default channel
    PCFMessageAgent agent = new PCFMessageAgent(host, port, channel);

    // Create the PCF message type for the inquire.
    PCFMessage pcfCmd = new PCFMessage(MQConstants.MQCMD_INQUIRE_Q_NAMES);
    // Queue name = wildcard.
    pcfCmd.addParameter(MQConstants.MQCA_Q_NAME, "*");
    // Queue type = ALL.
    pcfCmd.addParameter(MQConstants.MQIA_Q_TYPE, MQConstants.MQQT_ALL);

    // Execute the command. The returned object is an array of PCF messages.
    PCFMessage[] pcfResponse = pcfCM.agent.send(pcfCmd);

    // e.g. extract the queue names from the response object
    String[] names = (String[])pcfResponse[0].getParameterValue(MQConstants.MQCACF_Q_NAMES);
}

Alternatively you can put the PCF messages on the MQ queue (SYSTEM.ADMIN.COMMAND.QUEUE if you're on anything but z/OS) that the queue manager is listening for events on. You will then also need to define a 'reply to' queue in your message. You can do this from broker with an MQOutput node.

However that means you need to know the exact format of the PCF message that you want to send and what it's reply will look like, I think it is much easier to use the provided Java examples to do the message processing and formatting for you.

查看更多
登录 后发表回答