关闭

IBM MQQueueManager 直接连接

2684人阅读 评论(0) 收藏 举报
分类:
package com.xiuye.mq;

import java.io.IOException;
import java.util.Properties;

import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;

public class SendMsgMQ2 {

	public static void main(String[] args) throws MQException, IOException {
		Properties props = new Properties();
		props.put("hostname", "192.168.1.120");
		props.put("port",1415);
		props.put("channel", "MsgChannel");
		props.put("CCSID",1381);//数字
		
//		props.put("transport", "transmit");
		
		//以下正确
//		MQEnvironment.hostname = "localhost";
//		MQEnvironment.port=1415;
//		MQEnvironment.userID = "MUSR_MQADMIN";//可以不要
//		MQEnvironment.password = "";//可以不要
//		MQEnvironment.channel = "MsgChannel";
//		MQEnvironment.CCSID = 1381;
		
		System.out.println(MQEnvironment.hostname);
		System.out.println(MQEnvironment.port);
		System.out.println(MQEnvironment.CCSID);
		System.out.println(MQEnvironment.getQueueManagerReference(1));
		
		System.out.println(MQEnvironment.getDefaultConnectionManager());
		
		
		
		MQQueueManager manager = new MQQueueManager("QM1",props);
		
		System.out.println(manager.getResolvedObjectString());
		System.out.println(manager.name);
		System.out.println(manager.getDescription());
		System.out.println(manager.getName());
		System.out.println(manager.getAlternateUserId());
		System.out.println(manager.getCharacterSet());
		System.out.println(manager.getCloseOptions());
		System.out.println(manager.getCommandLevel());
		System.out.println(manager.getOpenOptions());
				
		int openOptions = 16;
		MQQueue q = manager.accessQueue("localq", openOptions);
		
		MQMessage putMessage = new MQMessage();
		putMessage.writeUTF("TEST");
		MQPutMessageOptions pmo = new MQPutMessageOptions();
		q.put(putMessage,pmo);
		
		System.out.println("Message has been input into the remote queue");
		q.close();
		
		manager.disconnect();
		
		
		
	}
	
}

1414
819
null
null
null
QM1
                                                                
QM1

1381
0
750
32
Message has been input into the remote queue


package com.xiuye.mq;

import java.io.IOException;
import java.util.Properties;

import com.ibm.mq.MQC;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;

public class ReceiveMsgMQ2 {

	public static void main(String[] args) throws MQException, IOException {

		Properties props = new Properties();
//		props.put("hostname", "localhost");
//		props.put("port", 1415);
		props.put("hostname", "192.168.1.120");
		props.put("port",1415);
		props.put("channel", "MsgChannel");
		props.put("CCSID",1381);//数字
		MQQueueManager manager = new MQQueueManager("QM1", props);

		@SuppressWarnings("deprecation")
		int openOptions = MQC.MQOO_INPUT_AS_Q_DEF;
		MQQueue q = manager.accessQueue("localq", openOptions);

		MQGetMessageOptions gmo = new MQGetMessageOptions();
		MQMessage msg = new MQMessage();
		q.get(msg, gmo);

		System.out.println(msg.readUTF());

		q.close();

		manager.disconnect();

	}

}
TEST



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:166266次
    • 积分:4825
    • 等级:
    • 排名:第6568名
    • 原创:314篇
    • 转载:97篇
    • 译文:0篇
    • 评论:18条
    文章分类
    最新评论