MQ出现2059错误如何快速断开

saka00 2012-03-28 02:33:24
是这样的,我用JAVA写了一个连接MQ的接口,在使用过程中发现,业务功能在调用此接口后,如果MQ连接出现问题
会出现比较长时间的等待,由于数据处理是放在一个事物中的,这样就会导致功能页面长时间静止。
请问如何解决此问题。
public String sentData(){


String qManager = manger; //QueueManager name
String qName = qname;//Queue Name
MQQueueManager qMgr = null;
MQQueue queue = null ;
try {
//configure connection parameters
MQEnvironment.hostname=hostname;//MQ Server name or IP
//MQEnvironment.port=1414;//listenr port
if(log.isDebugEnabled())
log.debug("Connecting to queue hostname: "+hostname);
MQEnvironment.channel=channel;//Server-Connection Channel
if(log.isDebugEnabled())
log.debug("Connecting to queue channel: "+channel);
MQEnvironment.CCSID =ccsid;
if(log.isDebugEnabled())
log.debug("Connecting to queue ccsid: "+ccsid);
// Create a connection to the QueueManager
if(log.isDebugEnabled())
log.debug("Connecting to queue MQQueueManager: "+qManager);

qMgr = new MQQueueManager(qManager);
// Set up the options on the queue we wish to open
//int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
int openOptions = MQC.MQOO_OUTPUT|MQC.MQOO_BIND_ON_OPEN|MQC.MQOO_FAIL_IF_QUIESCING ;//-----------------
// Now specify the queue that we wish to open and the open options
if(log.isDebugEnabled())
log.debug("Accessing queue: "+qName);

queue = qMgr.accessQueue(qName, openOptions);
// Define a simple WebSphere MQ Message ...
MQMessage msg = new MQMessage();
// ... and write some text in UTF8 format

//File file = new File("d:\\sd.000000129497.00000001.13500201.data");


// for(int m=0;m<187;m++){
// System.out.print(""+data[m]);
//
// }

//data=getBytesFromFile(file);
//FileOutputStream fos = new FileOutputStream(new File("D:/data.txt"));
//写入文件
//fos.write(data);


// for(int m=0;m<datalength;m++){
// System.out.print(" "+data[m]);
//
// }



String head="";
for(int m=recvcode.length();m<8;m++){
head=head+"0";
}
recvcode=head+recvcode;


recv=recvcode.getBytes();

msg.correlationId=recv;



//Specify the default put message options
MQPutMessageOptions pmo = new MQPutMessageOptions();
int totallen;
int totalduan;
// int messlen = 8*1024;
totallen = 0;
totalduan = 0;
// 2011-1-13 玄加林调整--解决数据量大时发送失败的问题
// while((totallen + messlen) < datalength)////8888888
// {
// pmo.options = 32770;//---------------------------
// msg.messageFlags = 2;//-----------------------
// msg.write(data,totallen,messlen);//8888888888888
// queue.put(msg, pmo);
// totallen += messlen;
// totalduan ++;
// }
msg.messageFlags = 4;
msg.write(data,totallen,datalength-totallen);
queue.put(msg, pmo);
totalduan++;
// Put the message to the queue
if(log.isDebugEnabled())
log.debug("Sending a message...");
return "发送成功";

}
catch (MQException ex) {
//出现异常直接关闭连接
try {
if(qMgr != null){
qMgr.disconnect();
}
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(log.isDebugEnabled())
log.debug("A WebSphere MQ Error occured : Completion Code "
+ ex.completionCode + " Reason Code " + ex.reasonCode);
return "发送失败";
}
catch (java.io.IOException ex) {

if(log.isDebugEnabled())
log.debug("An IOException occured whilst writing to the message buffer: "
+ ex);
return "发送失败";
}
finally{ //根据玄加林的要求,增加关闭mq连接的操作 2010-12-21 ---linpeng
try {
queue.close();
} catch (MQException e) {
// TODO Auto-generated catch block
try {
qMgr.disconnect();
} catch (MQException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
try {
qMgr.disconnect();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
...全文
1752 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zx_diy 2012-08-27
  • 打赏
  • 举报
回复
加入错误代码
W99841 2012-07-19
  • 打赏
  • 举报
回复
加入错误返回代码
sun007700 2012-04-10
  • 打赏
  • 举报
回复
有定义超时时间吗?
sun007700 2012-04-10
  • 打赏
  • 举报
回复
代码整理下。。没法看。
sun007700 2012-04-10
  • 打赏
  • 举报
回复
有定义超时时间吗?
JasonYao 2012-04-01
  • 打赏
  • 举报
回复
有定义超时时间吗?
JasonYao 2012-04-01
  • 打赏
  • 举报
回复
代码整理下。。没法看。
saka00 2012-03-30
  • 打赏
  • 举报
回复
已解决,捕捉异常后
switch (ex.reasonCode)
{
//连接断开
case 2009:
//队列管理者无效或未知
case 2058:
//队列管理者无效
case 2059:
//意外的错误发生
case 2195:
//服务器正在启动
case 2161:
//服务器正在关闭
case 2162:
//无权访问服务器队列管理者
case 2035:
//其他异常
default:

}
根据异常类型马上进行处理,也可捕捉异常后马上关闭连接
try {
if(qMgr != null){
qMgr.disconnect();
}
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

2,633

社区成员

发帖
与我相关
我的任务
社区描述
WebSphere 是 IBM 的软件平台。它包含了编写、运行和监视全天候的工业强度的随需应变 Web 应用程序和跨平台、跨产品解决方案所需要的整个中间件基础设施,如服务器、服务和工具。
社区管理员
  • WebSphere社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧