MQ通道重新启动代码给出错误

时间:2013-05-14 11:42:45

标签: java ibm-mq

我编写了一些Java代码来启动和停止MQ通道。我在MQ上创建了一个服务器连接通道来测试这段代码。但是在执行Java代码时,通道的启动和停止都会产生错误。

停止频道会出现以下错误:

about to stop channel
MQJE001: Completion Code 2, Reason 2202

启动频道会出现以下错误:

com.ibm.mq.MQException: MQJE001: An MQException occurred: Completion Code 2, Reason 2009
MQJE016: MQ queue manager closed channel immediately during connect
Closure reason = 2009

代码:

package com.asm.MQListenerChannelRestart;

import com.ibm.mq.pcf.*;
import com.ibm.mq.*;
import com.ibm.mq.pcf.CMQCFC;


public class MQListenerChannelRestart implements CMQCFC  {

    public void startChannel(PCFAgent pcfAgent){
        PCFParameter [] parameters = new PCFParameter [] {
                new MQCFST (MQCACH_CHANNEL_NAME, "TESTChanne"),
                new MQCFST(MQCACH_USER_ID,"user"),
                new MQCFST(MQCACH_PASSWORD,"password")
             };


        try {

            System.out.println("about to start channel");
            MQMessage [] pcfResponses = pcfAgent.send (MQCMD_START_CHANNEL, 
                                                  parameters);

            MQCFH cfh = new MQCFH(pcfResponses[0]);
            System.out.println("Parameter count="+cfh.parameterCount);
            System.out.println("Reason = "+cfh.reason);
            System.out.println(cfh.toString());

            pcfResponses = pcfAgent.send(MQCMD_INQUIRE_CHANNEL_STATUS, parameters);
            cfh = new MQCFH(pcfResponses[0]);
            System.out.println("Channel status is ==="+cfh.toString());
        } catch (Exception e) {
          e.printStackTrace();
        }
    }

    public void stopChannel(PCFAgent pcfAgent){
        PCFParameter [] parameters = new PCFParameter [] {
                new MQCFST (MQCACH_CHANNEL_NAME, "TESTChanne"),
                new MQCFIN (MQIACF_QUIESCE, MQQO_NO )
               };


        try {

            System.out.println("about to stop channel");
            MQMessage [] pcfResponses = pcfAgent.send (MQCMD_STOP_CHANNEL, 
                                                  parameters);

            MQCFH cfh = new MQCFH(pcfResponses[0]);
            System.out.println("Parameter count="+cfh.parameterCount);
            System.out.println("Reason = "+cfh.reason);
            System.out.println(cfh.toString());

            pcfResponses = pcfAgent.send(MQCMD_INQUIRE_CHANNEL_STATUS, parameters);
            cfh = new MQCFH(pcfResponses[0]);
            System.out.println("Channel status is ==="+cfh.toString());
        } catch (Exception e) {
          e.printStackTrace();
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        PCFAgent pcfAgent = null;


        MQListenerChannelRestart mqListenerChannelRestart = new MQListenerChannelRestart();
        mqListenerChannelRestart.stopChannel(pcfAgent);
        mqListenerChannelRestart.startChannel(pcfAgent);
    }

}

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

首先,你从未真正实例化过PCFAgent对象。

其次,您通过PCFMessageAgent将PCF命令发送到队列管理器。 PCFMessageAgent实际上扩展了PCFAgent,因此创建了PCFMessageAgent的对象。

第三,我不认为来自PCFCommand的响应可以保存在MQMessage中,而是应该在PCFMessage中进行。

您应该做的是阅读有关PCF here

的更多信息

此处有一个非常好的PCF_CommonMethods示例:ftp:// 119.44.222.58/opt/mqm/samp/pcf/samples/PCF_CommonMethods.java

截至目前,您希望编写如下代码:

 PCFMessageAgent agent = new PCFMessageAgent ("localhost", 1414, "CLIENT");
 PCFParameter [] parameters = new PCFParameter [] {
            new MQCFST (MQCACH_CHANNEL_NAME, "TESTChanne"),
            new MQCFST(MQCACH_USER_ID,"user"),
            new MQCFST(MQCACH_PASSWORD,"password")
         };

       PCFMessage   request = new PCFMessage (MQCMD_START_CHANNEL,parameters);

       PCFMessage []   responses = agent.send (request);