zoukankan      html  css  js  c++  java
  • 如何在java中使用WebSphere MQ?

    Java中使用websphere websphere mq:用于传输信息 具有跨平台的功能。

      1 安装websphere mq并启动

      2 websphere mq建立queue Manager(如:MQSI_SAMPLE_QM)

      3 建立queue类型选择Local类型的(如lq)

      4 建立channels类型选择Server Connection(如BridgeChannel)

    以下是引用片段:
    package test.mq; 
    import com.ibm.mq.*; 
    /* * ?????mq ?java ? */ 
    public class FirstMqTest 
    {// public static void main(String[] args[]) 
    {// FirstMqTest first = new FirstMqTest();// first.test();// } 
    public static void main(String args[]) 
    { FirstMqTest first = new FirstMqTest(); first.test(); } 
    public void test() 

    String qManager = "MQSI_SAMPLE_QM"; 
    //QueueManager name 
    String qName = "lq"; 
    //Queue Name try 
    { //configure connection parameters 
    MQEnvironment.hostname="172.16.17.123"; 
    //MQ Server name or IP 
    MQEnvironment.port=1414; 
    //listenr port 
    MQEnvironment.channel="BridgeChannel"; 
    //Server-Connection Channel M 
    QEnvironment.CCSID =1381; 
    // Create a connection to the QueueManager 
    System.out.println("Connecting to queue manager: "+qManager); 
    MQQueueManager qMgr = new MQQueueManager(qManager); 
    // Set up the options on the queue we wish to open 
    int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT; 
    // Now specify the queue that we wish to open and the open options 
    System.out.println("Accessing queue: "+qName); 
    MQQueue queue = qMgr.accessQueue(qName, openOptions); 
    // Define a simple WebSphere MQ Message ... 
    MQMessage msg = new MQMessage(); 
    // ... and write some text in UTF8 
    format msg.writeUTF("Hello, World!"); 
    // Specify the default put message options 
    MQPutMessageOptions pmo = new MQPutMessageOptions(); 
    // Put the message to the queue 
    System.out.println("Sending a message..."); 
    /* * ?????? mq ????? * */ 
    for(int j=0;j%26lt;5;j++) 
    { String str ="test11111111111"; 
    str = str+j; msg.writeUTF(str); 
    queue.put(msg, pmo); } 
    queue.put(msg, pmo); 
    // Now get the message back again. First define a WebSphere MQ message 
    // to receive the data 
    MQMessage rcvMessage = new MQMessage(); 
    // Specify default get message options 
    MQGetMessageOptions gmo = new MQGetMessageOptions(); 
    // Get the message off the queue. 
    System.out.println("...and getting the message back again"); 
    queue.get(rcvMessage, gmo); 
    // And display the message text... 
    String msgText = rcvMessage.readUTF(); 
    System.out.println("The message is: " + msgText); 
    // Close the queue 
    System.out.println("Closing the queue"); 
    queue.close(); 
    // Disconnect from the QueueManager 
    System.out.println("Disconnecting from the Queue Manager"); 
    qMgr.disconnect(); 
    System.out.println("Done!"); 

    catch (MQException ex) { 
    System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode + " Reason Code " + ex.reasonCode); } 
    catch (java.io.IOException ex) 

    System.out.println("An IOException occured whilst writing to the message buffer: " + ex); 


    }

  • 相关阅读:
    和时间做朋友:你一定要学的高效时间管理术
    助推:如何做出有关健康、财富与幸福的最佳决策(2017年诺贝尔经济学奖获得者理查德·泰勒作品)
    看透 : 解密身体语言隐藏的密码
    成为独角兽:海盗、梦想家、创新者如何开创并主宰新品类
    极简法则:从苹果到优步的深层简化工具
    高效15法则:谷歌、苹果都在用的深度工作发
    成功与运气:好运与精英社会的神话
    2星|《成长企业的法则》:尝试总结成功企业的模式,但是洞察力不够。
    3星|《OKR:源于英特热和谷歌的目标管理利器》:OKR原理、实施手册、实施过的公司的访谈
    gedit如何使用代码片段
  • 原文地址:https://www.cnblogs.com/java20130722/p/3207021.html
Copyright © 2011-2022 走看看