JR 精品文章 - java 中使用websphere MQ
AD: jr (at) javaresearch.org


首页 | 动态 | 文章 | FAQ  | 新闻 | 下载 | 代码 | 工作 | 调查 | 术语 | 站点 | 图书 | 论坛 | 帮助 | 全部  

TOP | 交流 | 软件 | 专栏 | 开源 | 译/著 | 源码 | API  | 推荐 | FTP  | 积分 | 统计 | 搜索 | Blog | 我们  
首页 » 研究文集 » 服务器及中间件 搜索标题相关文章 搜索标题相关文章    评论此文章 发表评论     开始监控此文章 开始监控   加入收藏夹  加入收藏夹
java 中使用websphere MQ
wsy8080 原创   更新:2007-05-14 16:53:13  版本: 1.0   


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

    }
}

版权声明   给作者写信
本篇文章对您是否有帮助?  投票:         投票结果:     12       0
作者其它文章:
作者全部文章

这个文章共有 0 条评论
主题: Commons-logging + Log4j  入门指南 上一篇文章
返回文章列表 返回〔服务器及中间件〕
下一篇文章 主题: 中间件的理解


文字广告链接
        自主、快速定制基于JAVA的B/S业务系统          重量级企业在线自定义WEB报表平台
        Excel制表、零代码发布、打印、图表结合——快逸报表,免费、稳定、功能强大的java工具
        技术圈: 关于Java、dotNet、PHP、Ruby、奇客、Web2.0等更多资讯博客精选文章

关于 JR  |  版权声明  |  联系我们 

©2002-2006 JR 版权所有 沪ICP备05019622号