IBM WebSphere MQ资料

视频:http://v.youku.com/v_show/id_XNDg0MTk1NzI0.html

书:www.redbooks.ibm.com 搜索WebSphere MQ,然后在internet上搜索MQ Using Java.pdf

读文档:http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzaw.doc/jm10120_.htm

错误代码:http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=%2Fcom.ibm.mq.csqsao.doc%2Ffm20910_1.htm

CCSID对照表:http://www-01.ibm.com/software/globalization/ccsid/ccsid_registered.html

客户端日志:C:\IBM\WebSphereMQ\errors\AMQERR01.LOG

 服务端日志:C:\IBM\WebSphereMQ\Qmgrs\CSQ1\errors\AMQERR01.LOG (CSQ1是Queue Manager的名字)

2539解决办法(字符集的问题):
http://blog.163.com/iloveecho83@126/blog/static/172997525201011932034678/

2035解决方法(权限问题,见视频,共分3种情况)
1. 使用了系统的SYSTEM CHANNEL被拒(No Access)
2. 用户属于Administrator或*MQADMIN用户组(userid blocked)
3. 用户是一般用户但是没有访问QM的权限(insufficient authorityinsufficient authority to access object 'CSQ1'
解决办法:

C:\Users\IBM_ADMIN>setmqaut -m CSQ1 -t qmgr -p win_user +connect
The setmqaut command completed successfully.

C:\Users\IBM_ADMIN>


4.用户是一般用户但是没有访问Queue的权限(insufficient authorityinsufficient authority to access object 'TRIG.TEST'
解决办法:

C:\Users\IBM_ADMIN>setmqaut -m CSQ1 -t queue -n TRIG.TEST -p win_user +put
The setmqaut command completed successfully.

C:\Users\IBM_ADMIN>


dos下切换用户:runas空格/profile空格/user:用户空格cmd.exe,比如当前用户是cyper想切换到win_user下

C:\Users\IBM_ADMIN>runas /profile /user:win_user cmd.exe
Enter the password for win_user:
Attempting to start cmd.exe as user "ADMINIB-SVQQ157\win_user" ...

C:\Users\IBM_ADMIN>

 第一个丑陋但可用的程序:

 

public class MqController extends MultiActionController {
	private static String qmName = "CSQ1";
private static String qName = "TRIG.TEST";

private static MQQueueManager qMgr;
private static Hashtable properties = new Hashtable();
static {
	properties.put("hostname", "192.168.0.105");
	properties.put("port", new Integer(1414));
	properties.put("channel", "SYSTEM.ADMIN.SVRCONN");
	properties.put("CCSID", new Integer(1208));
	properties.put("transport", "MQSeries");
}

/**
 * Entry point.
 */
public ModelAndView go(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
	return new ModelAndView("mq");
}

/**
 * test put.
 */
public void putMsg(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
	JSONObject result = new JSONObject();
	try {
		String msg = request.getParameter("msg");
		MqHelper helper = new MqHelper();
		helper.sendMsg(msg);

		result.put("ok", "true");
		result.put("info", "success!");
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		result.put("ok", "false");
		result.put("error", e.getMessage());
	}

	renderJson(response, result);

}

/**
 * test get.
 */
public void getMsg(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {

	JSONObject result = new JSONObject();
	try {
		MqHelper helper = new MqHelper();
		String output = helper.getMsg();

		result.put("ok", "true");
		result.put("info", output);
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		result.put("ok", "false");
		result.put("error", e.getMessage());
	}

	renderJson(response, result);
}

private void renderJson(HttpServletResponse response, JSONAware json) {
	String content = json.toJSONString();
	try {
		response.getOutputStream().write(content.getBytes());
	} catch (IOException e) {
		e.printStackTrace();
	}
}

private final class MqHelper {
	public void sendMsg(String msg) throws Exception {
		MQQueue queue = null;
		try {
			// Create a connection to the queue manager
		qMgr = new MQQueueManager(qmName, properties);
		// Set up the options on the queue we wish to open...
		int openOptions = CMQC.MQOO_INPUT_AS_Q_DEF | CMQC.MQOO_OUTPUT;
		// Now specify the queue that we wish to open,
		// and the open options...
		queue = qMgr.accessQueue(qName, openOptions);

		// Define a simple WebSphere MQ message, and write some text in
		// UTF format..
		MQMessage putMessage = new MQMessage();
		putMessage.writeUTF(msg);
		// specify the message options...
		// accept the defaults, same as MQPMO_DEFAULT
		MQPutMessageOptions pmo = new MQPutMessageOptions();
		// put the message on the queue
		queue.put(putMessage, pmo);
		logger.debug("Message has been input into the Remote Queue");

	} finally {
		if (queue != null) {
			// Close the queue...
			queue.close();
		}
		if (qMgr != null) {
			// Disconnect from the queue manager
			qMgr.disconnect();
		}
	}
}

public String getMsg() throws Exception {
	String result = "";
	MQQueue queue = null;
	try {
		// Create a connection to the queue manager
		qMgr = new MQQueueManager(qmName, properties);
		// Now specify the queue that we wish to open,
		// and the open options...
		int openOptions = CMQC.MQOO_INPUT_SHARED;
		queue = qMgr.accessQueue(qName, openOptions);

		MQMessage theMessage = new MQMessage();

		// specify the message options...
		MQGetMessageOptions gmo = new MQGetMessageOptions();
		queue.get(theMessage, gmo);

		int length = theMessage.getMessageLength();
		if (length > 0) {
			byte buffer[] = new byte[length];
			theMessage.readFully(buffer, 0, length);
			result = new String(buffer);
		} 
		
	} finally{
		if (queue != null) {
			// Close the queue...
			queue.close();
		}
		if (qMgr != null) {
			// Disconnect from the queue manager
				qMgr.disconnect();
			}
		}

		return result;
	}
}
}


所需要的jar包来自MQ Client,
IBM WebSphere MQ资料

 

 

你可能感兴趣的:(IBM WebSphere MQ资料)