【问题标题】:MQ Channel restart from code giving error从给出错误的代码重新启动 MQ 通道
【发布时间】:2015-04-14 02:22:55
【问题描述】:

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

停止频道出现以下错误:

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

Start Channel 出现以下错误:

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);
    }

}

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

【问题讨论】:

  • 对代码块使用一致且符合逻辑的缩进。代码的缩进是为了帮助大家理解程序流程!
  • 请给出完整的sn-p,特别是创建pcfAgent对象的代码。
  • 我现在已经提供了整个代码...谢谢

标签: java ibm-mq


【解决方案1】:

首先,您从未真正实例化您的 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    相关资源
    最近更新 更多