從零開始學(xué)Java

          一點一滴的積累才是學(xué)習(xí)的最高境界

          轉(zhuǎn):WebShpere MQ 配置與測試

          在“WebSphere 
          MQ程序設(shè)計初探”一文中,討論了從MQ隊列管理器的本地隊列中放置和讀出消息的程序,本文主要通過兩臺機器,搭建 MQ消息傳輸?shù)沫h(huán)境,并編寫測試程序進行測試。
          第一、準(zhǔn)備工作
          準(zhǔn)備2臺Win2000環(huán)境(XP也可),通過以太網(wǎng)連通。
          機器A:代碼為00000000,IP地址為:10.1.1.1
          機器B:代碼為88888888,IP地址為:10.1.1.2
          安裝MQ 5.3

          第二、創(chuàng)建MQ對象
          A機器上:
          1、打開“WebSphere MQ資源管理器”,新建隊列管理器,名稱為QM_00000000,其余采用默認設(shè)置;
          2、在QM_00000000隊列管理器中創(chuàng)建本地隊列,名稱為LQ_00000000;
          3、創(chuàng)建傳輸隊列,名稱為XQ_88888888(新建時選擇“本地隊列”,將“用法”設(shè)置為“傳輸”);
          4、創(chuàng)建遠程隊列定義,名稱為RQ_88888888,指定遠程隊列名稱為LQ_88888888,遠程隊列管理器名稱為QM_88888888,傳輸隊 列名稱為XQ_88888888;
          5、創(chuàng)建發(fā)送方通道,名稱為00000000.88888888,傳輸協(xié)議為TCP/IP,連接名稱為10.1.1.2(1414),傳輸隊列為 XQ_88888888;
          6、創(chuàng)建接受方通道,名稱為88888888.00000000,采用默認設(shè)置;
          7、創(chuàng)建服務(wù)器連接通道,名稱為DC.SVRCONN,采用默認設(shè)置(該通道主要給后面的測試程序使用)。
          B機器和A機器上的操作一樣,只是命名不同,如下:
          1、打開“WebSphere MQ資源管理器”,新建隊列管理器,名稱為QM_88888888,其余采用默認設(shè)置;
          2、在QM_88888888隊列管理器中創(chuàng)建本地隊列,名稱為LQ_88888888;
          3、創(chuàng)建傳輸隊列,名稱為XQ_00000000(新建時選擇“本地隊列”,將“用法”設(shè)置為“傳輸”);
          4、創(chuàng)建遠程隊列定義,名稱為RQ_00000000,指定遠程隊列名稱為LQ_00000000,遠程隊列管理器名稱為QM_00000000,傳輸隊 列名稱為XQ_00000000;
          5、創(chuàng)建發(fā)送方通道,名稱為88888888.00000000,傳輸協(xié)議為TCP/IP,連接名稱為10.1.1.1(1414),傳輸隊列為 XQ_00000000;
          6、創(chuàng)建接受方通道,名稱為00000000.88888888,采用默認設(shè)置;
          7、創(chuàng)建服務(wù)器連接通道,名稱為DC.SVRCONN,采用默認設(shè)置。

          第三、消息測試
          在A、B機器上分別啟動其發(fā)送方通道,正常情況通道狀態(tài)應(yīng)為“正在運行”。
          通過如下測試程序進行測試,文件名為:MQTest.java,在機器A上進行運行(如在B上運行請讀者自行適當(dāng)修改)。
          -------------------------------------------------------------------------------------------
           1 import java.io.IOException;
           2 import java.util.Hashtable;
           3 
           4 import com.ibm.mq.MQException;
           5 import com.ibm.mq.MQMessage;
           6 import com.ibm.mq.MQPutMessageOptions;
           7 import com.ibm.mq.MQQueue;
           8 import com.ibm.mq.MQQueueManager;
           9 
          10 public class MQSample{
          11     //定義隊列管理器和隊列的名稱 
          12     private static String qmName = "QM_00000000"
          13     private static String qName = "RQ_88888888";
          14     
          15     private static MQQueueManager qMgr; 
          16     private static Hashtable properties = new Hashtable();
          17 
          18     public static void main(String args[]) {
          19         try {
          20             properties.put("hostname""10.1.1.1");
          21             properties.put("port"new Integer(1414));
          22             properties.put("channel""DC.SVRCONN");
          23             properties.put("CCSID"new Integer(1381));
          24             properties.put("transport","MQSeries");
          25             
          26             // Create a connection to the queue manager 
          27             qMgr = new MQQueueManager(qmName,properties); 
          28             // Set up the options on the queue we wish to open 
          29             int openOptions = 16;
          30             // Now specify the queue that we wish to open, 
          31             // and the open options 
          32             MQQueue remoteQ = qMgr.accessQueue(qName, openOptions); 
          33             
          34             // Define a simple WebSphere MQ message, and write some text in UTF format.. 
          35             MQMessage putMessage = new MQMessage(); 
          36             putMessage.writeUTF("Test"); 
          37             // specify the message options 
          38             MQPutMessageOptions pmo = new MQPutMessageOptions(); 
          39             // accept the defaults, same as MQPMO_DEFAULT
          40             // put the message on the queue 
          41             remoteQ.put(putMessage,pmo); 
          42             System.out.println("Message has been input into the Remote Queue");
          43 
          44             // Close the queue 
          45             remoteQ.close(); 
          46             // Disconnect from the queue manager 
          47             qMgr.disconnect(); 
          48         }catch (MQException ex) { 
          49             // If an error has occurred in the above, try to identify what went wrong 
          50             // Was it a WebSphere MQ error? 
          51             System.out.println("A WebSphere MQ error occurred : Completion code " + ex.completionCode + 
          52           " Reason code " + ex.reasonCode); 
          53         }catch (IOException ex) { 
          54             // Was it a Java buffer space error? 
          55             System.out.println("An error occurred whilst writing to the message buffer: " + ex); 
          56         }catch(Exception ex){
          57             ex.printStackTrace();
          58         }
          59     }
          60 }

          posted on 2010-06-15 15:30 Eason Wu 閱讀(704) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          公告

          Java Java Java

          導(dǎo)航

          <2010年6月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 巨鹿县| 息烽县| 谢通门县| 灌阳县| 青海省| 油尖旺区| 怀化市| 台安县| 莱阳市| 城固县| 金寨县| 沭阳县| 扶余县| 昌乐县| 敦化市| 牙克石市| 万年县| 垣曲县| 乌海市| 深泽县| 桃园县| 绥阳县| 明光市| 司法| 昭通市| 许昌市| 禄劝| 南部县| 罗源县| 丹寨县| 溧水县| 扶沟县| 赞皇县| 淄博市| 资兴市| 丹凤县| 固原市| 桦甸市| 新昌县| 东乌珠穆沁旗| 嘉黎县|