网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 
中国网管联盟
Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道
 当前位置: > bitsCN.com > JAVA > 新手入门 > 开发工具 > java 中使用websphere MQ  

java 中使用websphere MQ

2007-05-20  作者:bitsCN整理  来源:wsy8080  点评 投稿 收藏

    java 中使用websphere

    websphere mq  : 用于传输信息 具有跨平台的功能。
1 安装websphere mq 并启动
2 websphere mq 建立 queue Manager (如:MQSI_SAMPLE_QM)
3 建立queue 类型选择 Local类型 的 (如lq  )
3 建立channels 类型选择Server Connection (如BridgeChannel)


    java 代码如下:


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[]){

网管有家www.bitscn.net


        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 网管联盟bitsCN_com
                    MQEnvironment.channel="BridgeChannel";//Server-Connection Channel
                    MQEnvironment.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  网管联盟bitsCN@com
                    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 ...  网管有家bitscn.net
                    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

网管有家bitscn.net


                    System.out.println("Sending a message...");
                    
                    /*
                     * 在此测试一下 mq 的传输次列
                     * 
                     */
                     for(int j=0;j<5;j++){ 网管网www_bitscn_com
                         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  网管网www.bitscn.com
                    // to receive the data 
                    MQMessage rcvMessage = new MQMessage();
                    
                    // Specify default get message options 
                    MQGetMessageOptions gmo = new MQGetMessageOptions();
                    // Get the message off the queue.
网管朋友网www_bitscn_net

                    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 网管有家bitscn.net
                    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!");
                }
网管u家bitscn.net

                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: "

网管网www_bitscn_com


                            + ex);
                }

    }
}
TAGs   使用       the    //    System.out.println   message       
 上一篇:Eclipse Template与模式   下一篇:使用JMock来实现孤立测试
java 中使用websphere MQ 评论:
loading.. 评论加载中…
评论:请自觉遵守互联网相关政策法规,评论不得超过250字。

验证码: 注册用户
本类热门排行:
最新推荐文章:
网管论坛交流: