日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Websphere MQ 开发实例

發布時間:2025/7/14 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Websphere MQ 开发实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • IBM MQSeries基本由一個消息傳輸系統和一個應用程序接口組成,其資源是消息和隊列(Messaging and Queuing)。 隊列管理器(Queue Manager):管理隊列的系統,實現網絡通信,保證消息安全可靠地傳輸到目的地。
  • 用于確保隊列之間的信息提供,包括網絡中不同系統上的的遠程隊列之間的信息提供。并保證網絡故障或關閉后的恢復。
  • 隊列:一個安全的信息存儲區。因為信息存放在隊列中,所以應用程序可以相互獨立的運行,以不同的速度,在不同的時間,在不同的地點。
  • 本地隊列:對程序而言,本地隊列屬于該程序所連接的隊列管理器。
  • 遠程隊列:該隊列不屬于該程序所連接的隊列管理器,而只是遠端隊列管理器的隊列在本地的定義。
  • 傳輸隊列:它是一個本地隊列,保存了指定要發送到遠端的消息。
  • 死信隊列:它是一個本地隊列,用于存放無法傳遞的消息。
  • 通道:在兩個隊列管理器之間建立起來的數據傳輸鏈路。
  • 應用程序接口:應用程序和信息系統之間通過MQSeries API實現的接口。
  • ?

    ?

    import com.ibm.mq.MQC;
    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 Send {

    ?public static void main(String[] args) {
    ?? try {

    ????? // 主機名稱
    ????? String hostName = "192.168.1.101";
    ????? // 端口(缺省 1414)
    ????? int port = 1515;
    ????? // 通道名稱(缺省)
    ????? String channel = "SYSTEM.DEF.SVRCONN";
    ????? // 隊列管理器名稱
    ????? String qManager = "send";
    ????? // 隊列名稱 (遠程隊列名)
    ????? String qName = "Q1";

    ????? // Set up the MQEnvironment properties for Client Connections.
    ????? // 建立MQEnvironment 屬性以便客戶機連接.
    ????? MQEnvironment.hostname = hostName;
    ????? MQEnvironment.port = port;
    ????? MQEnvironment.channel = channel;
    ????? MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
    ????? MQEnvironment.CCSID = 1381;
    ?????
    ????? // Connection To the Queue Manager.
    ????? // 連接到隊列管理器.
    ????? MQQueueManager qMgr = new MQQueueManager(qManager);

    ????? /**
    ?????? * Set up the open options to open the queue for out put
    ?????? * and additionally we have set the option to fail if the queue manager
    ?????? * is quiescing.
    ?????? *
    ?????? * 建立打開選項以便打開用于輸出的隊列,進一步而言,如果隊列管理器是
    ?????? * 停頓的話,我們也已設置了選項去應對不成功情況.
    ?????? */
    ????? int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;

    ????? // Open the queue.
    ????? // 打開隊列.
    ????? MQQueue queue = qMgr.accessQueue(qName, openOptions, null, null,
    ??????? null);

    ????? // Set the put message options , we will use the default setting.
    ????? // 設置放置消息選項我們將使用默認設置.
    ????? MQPutMessageOptions pmo = new MQPutMessageOptions();

    ????? /**
    ?????? * Next we Build a message The MQMessage class encapsulates the data
    ?????? * buffer that contains the actual message data, together with all the MQMD
    ?????? * parameters that describe the message.
    ?????? *
    ?????? * 下一步我們建立消息,MQMessage類壓縮了包含實際消息數據的數據緩沖區,
    ?????? * 和描述消息的所有MQMD 參數.
    ?????? *
    ?????? * To Build a new message, create a new instance of MQMessage class
    ?????? * and use writxxx (we will be using writeString method).
    ?????? * The put() method of MQQueue also takes an instance of the
    ?????? * MQPutMessageOptions class as a parameter.
    ?????? *
    ?????? * 欲建立新消息,創建MQMessage類新實例以及使用writxxx(我們將使用writeString 方法.).
    ?????? * MQQueue 的put()方法也可作為參數MQPutMessageOptions 類的實例.
    ?????? */

    ????? // Create The message buffer.
    ????? // 創建消息緩沖區.
    ????? MQMessage outMsg = new MQMessage();

    ????? // Set the MQMD format field.
    ????? // 設置MQMD 格式字段.
    ????? outMsg.format = MQC.MQFMT_STRING;
    ??????????????

    ????? // Prepare message with user data.
    ????? // 準備用戶數據消息.
    ????? String msgString = "HEAD7C5218991310615536?? BOCOMC???? 0100521899??????? 200909170720470020090917101000000022164428000000020000000000000000000000020000? 1110408715? 0000??? 0 1564439990000044399900000????????????????????????? 1 1? 000?????????????????????????????????????????????? DOMN200909170720470016100115400000000156????????? HA1310011130028738445 AT032007101900000068835700000110000000000000000020090915000000010000000000431643000000000000?????????????????????? PENG PING????????? 6532CAFCR102??????????????????????????????????????????????????????????????????? 000281548016372856DQPD??????? 2007100120071030?????????????????????????????? 000002000000000000000000000068835700000110000000000000000000000001000000000043164300000048411900000010000000620090917072055550????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 19790117?????????????????????????????????????????????????????????????? 518000????????? 20090917000000272977113714719646???????? 1310710130979?????? MALE??????????????????? SSNO180001016790???????????????????????????? MS0000000000??????????????? 2007101920090912000000002007103001????????????????? 0?????????? 00000004841192007102004064394C?????? 000000000?????????? TAIL";

    ????? // Now we put The message on the Queue.
    ????? // 現在我們在隊列上放置消息.
    ????? outMsg.writeString(msgString);


    ????? // Commit the transaction.
    ????? // 提交事務處理.
    ????? queue.put(outMsg, pmo);
    ????? qMgr.commit();
    ????? System.out.println(" The message has been Sussesfully put/n/n#########");

    ????? // Close the the Queue and Queue manager objects.
    ????? // 關閉隊列和隊列管理器對象.
    ????? queue.close();
    ????? qMgr.disconnect();

    ???? } catch (MQException ex) {

    ????? System.out.println("An MQ Error Occurred: Completion Code is :/t" +
    ????? ex.completionCode + "/n/n The Reason Code is :/t" + ex.reasonCode);
    ????? ex.printStackTrace();

    ???? } catch (Exception e) {

    ????? e.printStackTrace();

    ???? }

    ?}

    }

    ?

    ?

    import com.ibm.mq.MQC;
    import com.ibm.mq.MQEnvironment;
    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;

    /**
    ?* 消息接收器應用程序
    ?*
    ?* 調入MQSeries Java API package
    ?* 為客戶機連接設置環境屬性
    ?* 連接到隊列管理器
    ?* 為打開MQSeries 隊列設置選項
    ?* 為獲取消息打開應用程序
    ?* 設置選項,從應用程序隊列獲取消息
    ?* 創建消息緩沖區
    ?* 從隊列獲取消息到消息緩沖區
    ?* 從消息緩沖區讀取用戶數據并在控制臺上顯示
    ?*/

    public class Receiver {

    ? public static void PtpReceiver() {
    ??? try {
    ????
    ???? // 主機名稱
    ???? String hostName = "192.168.1.101";
    ???? // 端口(缺省 1414)
    ???? int port = 1616;
    ???? // 通道名稱(缺省)
    ???? String channel = "SYSTEM.DEF.SVRCONN";
    ???? // 隊列管理器名稱
    ???? String qManager = "receive";
    ???? // 隊列名稱 (本地對列名)
    ???? String qName = "Q1";

    ???? // 建立MQEnvironment 屬性以便客戶機連接
    ???? MQEnvironment.hostname = hostName;
    ???? MQEnvironment.port = port;
    ???? MQEnvironment.channel = channel;
    ???? MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
    ???? MQEnvironment.CCSID = 1381;
    ????
    ???? // Connection To the Queue Manager.
    ???? // 連接到隊列管理器.
    ???? MQQueueManager qMgr = new MQQueueManager(qManager);

    ???? /**
    ????? * Set up the open options to open the queue for out put and
    ????? * additionally we have set the option to fail if the queue manager
    ????? * is quiescing.
    ????? *
    ????? * 建立打開選項以便打開用于輸出的隊列,
    ????? * 進一步而言,如果隊列管理器是停頓的話,我們也
    ????? * 已設置了選項去應對不成功情況.
    ????? */

    ???? // Open the queue.
    ???? // 打開隊列.
    ???? int openOptions = MQC.MQOO_INPUT_SHARED | MQC.MQOO_FAIL_IF_QUIESCING;

    ???? // Set the put message options.
    ???? // 設置放置消息選項.
    ???? MQQueue queue = qMgr.accessQueue(qName, openOptions, null, null, null);

    ???? MQGetMessageOptions gmo = new MQGetMessageOptions();

    ???? // Get messages under sync point control.
    ???? // 在同步點控制下獲取消息.
    ???? gmo.options = gmo.options + MQC.MQGMO_SYNCPOINT;

    ???? // Wait if no messages on the Queue.
    ???? // 如果在隊列上沒有消息則等待.
    ???? gmo.options = gmo.options + MQC.MQGMO_WAIT;

    ???? // Fail if QeueManager Quiescing.
    ???? // 如果隊列管理器停頓則失敗.
    ???? gmo.options = gmo.options + MQC.MQGMO_FAIL_IF_QUIESCING;

    ???? // Sets the time limit for the wait.
    ???? // 設置等待的時間限制.
    ???? gmo.waitInterval = 3000;
    ????

    ???? /**
    ????? * Next we Build a message The MQMessage class encapsulates the data
    ????? * buffer that contains the actual message data, together with all the MQMD
    ????? * parameters that describe the message.
    ????? *
    ????? * 下一步我們建立消息,MQMessage
    ????? * 類壓縮了包含實際消息數據的數據緩沖區,
    ????? * 和描述消息的所有MQMD 參數.
    ????? */

    ???? // Create the message buffer.
    ???? // 創建消息緩沖區.
    ???? MQMessage inMsg = new MQMessage();

    ???? // Get the message from the queue on to the message buffer.
    ???? // 從隊列到消息緩沖區獲取消息.
    ???? queue.get(inMsg, gmo);

    ???? // Read the User data from the message.
    ???? // 從消息讀取用戶數據.
    ???? String msgString = inMsg.readString(inMsg.getMessageLength());
    ???? // 控制臺輸出
    ???? System.out.println(" The Message from the Queue is : /n/n" + msgString);

    ???? // Commit the transaction.
    ???? // 提交事務處理.
    ???? qMgr.commit();

    ???? // Close the the Queue and Queue manager objects.
    ???? // 關閉隊列和隊列管理器對象.
    ???? queue.close();
    ???? qMgr.disconnect();

    ??? } catch (MQException ex) {

    ???? System.out.println("An MQ Error Occurred: Completion Code is :/t" +
    ???? ex.completionCode + "/n/n The Reason Code is :/t" + ex.reasonCode);
    ???? ex.printStackTrace();

    ??? } catch (Exception e) {

    ???? e.printStackTrace();

    ??? }

    ?? }

    ?? /**
    ??? * @param args
    ??? */
    ?? public static void main(String[] args) {
    ??? // TODO Auto-generated method stub
    ??? PtpReceiver();
    ?? }

    }

    ?

    注意字符集問題

    一:MQEnvironment.CCSID = 1381;(在JAVA連接代碼時指定一下字符集)

    二:修改字符集設置

    一般Unix、Linux平臺中MQ默認的字符集為819,而Windows平臺為1381,所以你必須改變其字符集,使兩邊的字符集相同。改變方法:

    1.通過DOS進入MQ的安裝目錄,進入/bin下。假如要更改的隊列管理器為A

    2.用指令“strmqm A”啟動隊列管理器A

    3.用指令“runmqsc A”啟動A的MQSC。

    4.運行指令“ALTER QMGR CCSID(819)”“end”則修改字符集為819

    ?

    《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

    總結

    以上是生活随笔為你收集整理的Websphere MQ 开发实例的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。