當前位置:名人名言大全網 - 端午節短信 - mq java如何判斷隊列為空?

mq java如何判斷隊列為空?

MQ異常

這個類包含WebSphere MQ完成代碼和錯誤代碼常量的定義。以MQCC_開頭的常量是WebSphere MQ完成代碼,而以MQRC_開頭的常量是WebSphere MQ原因代碼。只要WebSphere MQ出現

錯誤,將給出MQException。

MQGetMessageOptions

此類包含控制MQQueue.get()方法行為的選項。

MQManagedObject

此類是MQQueueManager、MQQueue和MQProcess類的超類。它提供了查詢和設置這些資源屬性的能力。

-解決方案。

去拿壹次,得到2033錯誤,就是沒有符合妳要求的消息。

使用PCF查詢隊列數據:

/**

* @返回當前連接隊列的當前深度。

* @拋出異常

*/

public QueueInfo queryQueueInfo()引發異常{

如果(!check status 2(this . queue manager)){

拋出新的IllegalStateException("未連接到隊列管理器。");

}

PCFMessageAgent代理= null

嘗試{

agent = new PCFMessageAgent(this . queue manager);

//查詢隊列名稱& amp當前深度。

int[] attrs = {

CMQC。MQCA_Q_NAME。MQIA _當前_ Q _深度,

CMQC。MQIA_OPEN_INPUT_COUNT,CMQC。MQIA_OPEN_OUTPUT_COUNT

CMQC。MQIA_Q_TYPE,CMQC。MQIA_DEFINITION_TYPE。MQIA_INHIBIT_GET,

CMQC。MQIA _ INHIBIT _ PUT };

PCFParameter[]參數= {

新MQCFST(CMQC。MQCA_Q_NAME,getInputQueue()。getText()。trim()),

新MQCFIL(CMQCFC。MQIACF_Q_ATTRS,ATTRS)};

// logger.log("查詢當前隊列的當前深度。");

MQ message[]responses = agent . send(cmq CFC。MQCMD_INQUIRE_Q,參數);

queue info info = new queue info();

for(int I = 0;我& lt響應.長度;i++) {

MQ cfh cfh = new MQ cfh(responses[I]);

//檢查響應消息中的PCF頭(MQCFH)

if (cfh.reason == 0) {

字符串名稱= " ";

整數深度=新整數(0);

for(int j = 0;j & ltcfh.parameterCountj++) { //從返回的屬性中提取我們想要的東西

PCF parameter p = PCF parameter . next parameter(responses[I]);

switch (p.getParameter()) {

案例CMQC。MQCA_Q_NAME:

name =(String)p . getvalue();

info.name = name

打破;

案例CMQC。MQIA _當前_ Q _深度:

depth =(整數)p . getvalue();

info . depth = depth . int value();

打破;

案例CMQC。MQIA _開放_輸入_計數:

Integer input count =(Integer)p . getvalue();

info . input count = input count . int value();

打破;

案例CMQC。MQIA _打開_輸出_計數:

Integer output count =(Integer)p . getvalue();

info . output count = output count . int value();

打破;

案例CMQC。MQIA_Q_TYPE:

info.type = ((Integer) p.getValue())。int value();

打破;

案例CMQC。MQIA_DEFINITION_TYPE:

info . definition type =((Integer)p . getvalue())。int value();

打破;

案例CMQC。MQIA _抑制_輸出:

info . putnotallowed =((Integer)p . getvalue())。int value()= = 1;

打破;案例CMQC。MQIA_INHIBIT_GET:

info . getnotallowed =((Integer)p . getvalue())。int value()= = 1;

默認值:

}

}

//system . out . println(" Queue "+name+" curdepth "+depth);

返回信息;

}否則{

System.out.println("PCF錯誤:\ n "+cfh);

//遍歷描述錯誤的返回參數

for(int j = 0;j & ltcfh.parameterCountj++) {

system . out . println(PCF parameter . next parameter(responses[0]);

}

拋出新異常(" PCF Error[reason:"+cfh . reason+"]");

}

}

返回null

} catch(異常e) {

扔e;

}最後{

如果(代理!= null) {

嘗試{

agent . disconnect();

} catch(異常e) {

logger . log(e);

}

}

}