操作系统:Centos6 64bit
软件版本:websphere ND 8.5.5.0 websphere MQ 7.5.0.2
在was上的应用访问mq的队列放入消息,取出消息并存入数据库
放入信息时报错
com.ibm.mq.MQException:MQJE001:Completion Code ‘2’,Reason ‘2459’
取出消息消息时也报错Code ‘2’,Reason ‘2459’
有一阶段取出消息消息时报错Code ‘2’,Reason ‘2159’
1.在was控制台的环境->WebSphere变量->(新建)名称 MQ_INSTALL_ROOT 值/opt/mqm
2.修改自启动脚本
/etc/rc.local
export CLASSPATH=com.ibm.mq.axis2.jar:com.ibm.mq.commonservices.jar:com.ibm.mq.defaultconfig.jar:com.ibm.mq.headers.jar:com.ibm.mq.jar:com.ibm.mq.jmqi.jar:com.ibm.mqjms.jar:com.ibm.mq.jms.Nojndi.jar:com.ibm.mq.pcf.jar:com.ibm.mq.postcard.jar:com.ibm.mq.soap.jar:com.ibm.mq.tools.ras.jar
export LD_LIBRARY_PATH=/opt/mqm/java/lib64
/WebSphere/AppServer/profiles/AppSrv01/bin/startServer.sh server1
export EXTSHM=ON
su - mqm -c ‘/opt/mqm/bin/strmqm QM_hostb’
解决问题.
估计export CLASSPATH 那段去掉也能好用,主要是LD_LIBRARY_PATH
package mytest;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQC;
import com.ibm.mq.MQMessage;
import java.io.*;
public class MQGetBig60{
public static void main(String[] args)throws Exception {
System.out.println(“Begin!”);
//获得接收队列管理器
MQQueueManager QMgr=null;
String QMGR_Name_S=“QM”;
//获得接收队列
MQQueue queue=null;
String Q_Name_S=“as”;//“jz”;
//获得消息并存在本地
MQGetMessageOptions gmo = null;
//创建本地文件
File file = File.createTempFile(“dbcopy_”,".zip",new File("./"));
System.out.println(file.getAbsolutePath());
try {
QMgr=new MQQueueManager(QMGR_Name_S);
} catch(Throwable e) {
if(QMgr!=null) {
try {
QMgr.disconnect();
} catch(Exception ex){
System.out.println("ex"+ex);
}
}
System.out.println("在得到接收队列管理器"+'"'+QMGR_Name_S+'"'+"时发生异常:"+e.toString());
}
int openOptions=MQC.MQOO_INQUIRE|MQC.MQOO_BROWSE;
try {
queue=QMgr.accessQueue(Q_Name_S,openOptions);
} catch(Throwable e) {
if(queue!=null) {
try {
queue.close();
} catch(Exception ex){
System.out.println("ex"+ex);
}
}
System.out.println("在访问接收队列("+Q_Name_S+")时出错:"+e.toString());
}
try{
gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_COMPLETE_MSG|MQC.MQGMO_BROWSE_NEXT|MQC.MQGMO_NO_WAIT;
}catch(Exception e){
System.out.println("new MQGetMessageOptions() exception"+e);
}
MQMessage message = null;
FileOutputStream out = null;
try{
message = new MQMessage();
message.characterSet=1381;
queue.get(message,gmo);
byte b[] = new byte[message.getMessageLength()];
message.readFully(b);
out = new FileOutputStream(file);
out.write(b);
out.close();
queue.close();
QMgr.disconnect();
}catch(Exception x){
try{
if(out!=null)
out.close();
}catch(Exception ex){
System.out.println("ex"+ex);
}
System.out.println("类的get方法出现异常");
}
System.out.println("End!");
}
}
package weipengtest;
import main.core.Main;
import com.ibm.mq.MQC;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
public class ChangeError {
public static void main(String[] args) throws Exception {
Main.MyLog.info(“Begin!ChangeError!”);
MQQueueManager QMgr = null;
// 队列管理器名
String QMGR_Name_S = “QM_xxbrep”;
MQQueue queue_error = null;
// 错误队列名
String toqueuelaststr = “_error”;
// String toqueuelaststr=“zb”;
String Q_Name_Error = “bxdq_zb”;
// String Q_Name_Error=“qhddq_zb”;
MQQueue queue_zb = null;
// 转移到的队列名尽量不添让系统自动取xxx_zb
String Q_Name_Zb = null;
// String Q_Name_Zb=“qhddq_error”;
// MQ GET参数
MQGetMessageOptions gmo = null;
// MQ PUT参数
MQPutMessageOptions pmo = null;
try {
QMgr = new MQQueueManager(QMGR_Name_S);
} catch (Throwable e) {
if (QMgr != null) {
try {
QMgr.disconnect();
} catch (Exception ex) {
Main.MyLog.error(“ex” + ex);
}
}
Main.MyLog.error(“在得到队列管理器” + ‘"’ + QMGR_Name_S + ‘"’ + “时发生异常:” + e.toString());
}
int open_errorOptions = MQC.MQOO_INPUT_EXCLUSIVE;
try {
queue_error = QMgr.accessQueue(Q_Name_Error, open_errorOptions);
} catch (Throwable e) {
if (queue_error != null) {
try {
queue_error.close();
} catch (Exception ex) {
Main.MyLog.error(“ex” + ex);
}
}
Main.MyLog.error(“在访问错误队列(” + Q_Name_Error + “)时出错:” + e.toString());
}
if (Q_Name_Zb == null) {
Q_Name_Zb = Q_Name_Error.split("_")[0] + toqueuelaststr;
}
int open_zbOptions = MQC.MQOO_OUTPUT;
try {
queue_zb = QMgr.accessQueue(Q_Name_Zb, open_zbOptions);
} catch (Throwable e) {
if (queue_zb != null) {
try {
queue_zb.close();
} catch (Exception ex) {
Main.MyLog.error(“ex” + ex);
}
}
Main.MyLog.error(“在访问正常队列(” + Q_Name_Zb + “)时出错:” + e.toString());
}
try {
gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_SYNCPOINT;
} catch (Exception e) {
Main.MyLog.error(“new MQGetMessageOptions() exception” + e);
}
try {
pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_SYNCPOINT;
} catch (Exception e) {
Main.MyLog.error(“new MQGetMessageOptions() exception” + e);
}
MQMessage message = null;
try {
message = new MQMessage();
message.characterSet = 1381;
queue_error.get(message, gmo);
queue_zb.put(message, pmo);
} catch (Exception x) {
Main.MyLog.error(“queue_error.get(message,gmo) or queue_zb.put(message,pmo)方法出现异常” + x);
}
if (queue_error != null) {
try {
queue_error.close();
} catch (Exception e) {
}
}
}
}