2017-02-21 202 views
1

我已經使用下面的代碼來禁止隊列,但是當我嘗試禁止時出現錯誤。
我已經嘗試了特定隊列的各種打開選項,但仍然有問題。我的代碼中還遺漏了什麼?如何清除問題「com.ibm.mq.MQException:MQJE001:完成代碼2,原因2040」

 public void control(String mgrName, String queueName, int openOptions, string option)throws MQException{ 
    qMgr = new MQQueueManager(mgrName); 
     mqQueue = qMgr.accessQueue(queueName, openOptions);  
     if (option.equalsIgnoreCase("stop")){ 
      System.out.println("Stop mesage received"); 
      mqQueue.setInhibitGet(MQC.MQQA_GET_INHIBITED); 
      System.out.println("Queue inhibitted successfully"); 
     }else if(option.equalsIgnoreCase("start")){ 
      System.out.println("Start mesage received"); 
      mqQueue.setInhibitGet(MQC.MQQA_GET_ALLOWED); 
      System.out.println("Queue get allowed successfully"); 
     } 
} 

我在調用此方法時遇到了以下錯誤。
com.ibm.mq.MQException:MQJE001:完成代碼2,原因2040

回答

1

2040 = MQRC_NOT_OPEN_FOR_SET。 IBM的V7.5知識中心頁面「2040 (07F8) (RC2040): MQRC_NOT_OPEN_FOR_SET」描述了這個錯誤的原因:

Explanation

An MQSET call was issued to set queue attributes, but the queue had not been opened for set.

Programmer response

Specify MQOO_SET when the object is opened.

如果傳遞給controlopenOptions包括MQOO_SET那麼錯誤應該消失。下面

例子:

int openOptions = MQConstants.MQOO_FAIL_IF_QUIESCING | MQConstants.MQOO_SET 
+0

感謝@Josh,我已經使用舊版本的罐子。只有MQC接口不變。我發現MQOO_SET常量值爲64,並直接硬編碼,因此它按預期工作。感謝這個例子。 (我已經訪問過該網站,但我無法找到MQOO_SET,再次感謝您通知MQConstants) – Fresher

+0

MQOO_FAIL_IF_QUIESCING – Fresher

+0

@Fresher的用法是什麼,您使用的是哪個版本的jar文件? v7.1之前的任何MQ版本及其關聯的jar文件都不受支持。 7.1將於2017年4月30日退出支持。示例'MQSample.java'從'import com.ibm.mq.constants.MQConstants'中抽取MQConstans。 – JoshMc