microwin
发贴: 18
积分: 10
|
于 2003-10-27 15:03
/** * <p>Title: MQ实例测试程序!</p> * @author Microwin * @version 1.0 */ import com.ibm.mq.*;
public class ConnMQ4 {
private String qManager_name = "QM_P2P_XXXXX"; private String qQueue_name = "Q1"; private MQQueueManager mqQueueManager; private MQQueue mqQueue;
public ConnMQ4() { MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES); MQEnvironment.CCSID=1381; }
public void conn(){ try { mqQueueManager =new MQQueueManager(qManager_name); System.out.println("成功连接QueueManager"); //---------------------------------------- int openOptions = MQC.MQOO_INPUT_AS_Q_DEF|MQC.MQOO_OUTPUT; mqQueue = mqQueueManager.accessQueue(qQueue_name,openOptions); MQPutMessageOptions mpmo = new MQPutMessageOptions(); MQMessage mqMessage = new MQMessage(); mqMessage.writeInt(25); mqMessage.writeString("good"); mqQueue.put(mqMessage,mpmo); } catch (MQException ex) { System.out.println("Error Code : " + ex.reasonCode); ex.printStackTrace(); } catch(java.io.IOException ex){ ex.printStackTrace(); } finally { try { if(mqQueue!=null){ mqQueue.close(); System.out.println("成功关闭Queue"); } if(mqQueueManager!=null){ mqQueueManager.close(); mqQueueManager.disconnect(); System.out.println("成功关闭、断开QueueManager"); } } catch (MQException ex) {
}//end try-catch
}//end try-catch
}
public static void main(String[] args) { ConnMQ4 connMQ41 = new ConnMQ4(); connMQ41.conn(); } }
|