• WebShpereMQ配置与测试


    “WebSphere MQ程序设计初探一文中,讨论了从MQ队列管理器的本地队列中放置和读出消息的程序,本文主要通过两台机器,搭建MQ消息传输的环境,并编写测试程序进行测试。


    第一、准备工作


    准备2Win2000环境(XP也可),通过以太网连通。
    机器A:代码为00000000IP地址为:10.1.1.1
    机器B:代码为88888888IP地址为:10.1.1.2
    安装MQ 5.3


    第二、创建MQ对象


    A机器上:
    1、打开“WebSphere MQ资源管理器,新建队列管理器,名称为QM_00000000,其余采用默认设置;
    2
    、在QM_00000000队列管理器中创建本地队列,名称为LQ_00000000;
    3
    、创建传输队列,名称为XQ_88888888(新建时选择本地队列,将用法设置为传输;
    4
    、创建远程队列定义,名称为RQ_88888888,指定远程队列名称为LQ_88888888,远程队列管理器名称为QM_88888888,传输队列名称为XQ_88888888;
    5
    、创建发送方通道,名称为00000000.88888888,传输协议为TCP/IP,连接名称为10.1.1.2(1414),传输队列为XQ_88888888;
    6
    、创建接受方通道,名称为88888888.00000000,采用默认设置;
    7、创建服务器连接通道,名称为DC.SVRCONN,采用默认设置(该通道主要给后面的测试程序使用)。


    B机器和A机器上的操作一样,只是命名不同,如下:
    1、打开“WebSphere MQ资源管理器,新建队列管理器,名称为QM_88888888,其余采用默认设置;
    2
    、在QM_88888888队列管理器中创建本地队列,名称为LQ_88888888;
    3
    、创建传输队列,名称为XQ_00000000(新建时选择本地队列,将用法设置为传输;
    4
    、创建远程队列定义,名称为RQ_00000000,指定远程队列名称为LQ_00000000,远程队列管理器名称为QM_00000000,传输队列名称为XQ_00000000;
    5
    、创建发送方通道,名称为88888888.00000000,传输协议为TCP/IP,连接名称为10.1.1.1(1414),传输队列为XQ_00000000;
    6
    、创建接受方通道,名称为00000000.88888888,采用默认设置;
    7、创建服务器连接通道,名称为DC.SVRCONN,采用默认设置。


    第三、消息测试


    AB机器上分别启动其发送方通道,正常情况通道状态应为正在运行
    通过如下测试程序进行测试,文件名为:MQTest.java,在机器A上进行运行(如在B上运行请读者自行适当修改)。
     

    1. import java.io.IOException;
    2. import java.util.Hashtable;
    3. import com.ibm.mq.MQException;
    4. import com.ibm.mq.MQMessage;
    5. import com.ibm.mq.MQPutMessageOptions;
    6. import com.ibm.mq.MQQueue;
    7. import com.ibm.mq.MQQueueManager;
    8. public class MQSample{
    9.     //定义队列管理器和队列的名称
    10.     private static String qmName = "QM_00000000";
    11.     private static String qName = "RQ_88888888";
    12.    
    13.     private static MQQueueManager qMgr;
    14.     private static Hashtable properties = new Hashtable();
    15.     public static void main(String args[]) {
    16.         try {
    17.             properties.put("hostname", "10.1.1.1");
    18.             properties.put("port", new Integer(1414));
    19.             properties.put("channel", "DC.SVRCONN");
    20.             properties.put("CCSID", new Integer(1381));
    21.             properties.put("transport","MQSeries");
    22.             
    23.             // Create a connection to the queue manager
    24.             qMgr = new MQQueueManager(qmName,properties);
    25.             // Set up the options on the queue we wish to open...
    26.             int openOptions = 16;
    27.             // Now specify the queue that we wish to open,
    28.             // and the open options...
    29.             MQQueue remoteQ = qMgr.accessQueue(qName, openOptions);
    30.             
    31.             // Define a simple WebSphere MQ message, and write some text in UTF format..
    32.             MQMessage putMessage = new MQMessage();
    33.             putMessage.writeUTF("Test");
    34.             // specify the message options...
    35.             MQPutMessageOptions pmo = new MQPutMessageOptions();
    36.             // accept the defaults, same as MQPMO_DEFAULT
    37.             // put the message on the queue
    38.             remoteQ.put(putMessage,pmo);
    39.             System.out.println("Message has been input into the Remote Queue");
    40.             // Close the queue...
    41.             remoteQ.close();
    42.             // Disconnect from the queue manager
    43.             qMgr.disconnect();
    44.         }catch (MQException ex) {
    45.             // If an error has occurred in the above, try to identify what went wrong
    46.             // Was it a WebSphere MQ error?
    47.             System.out.println("A WebSphere MQ error occurred : Completion code " + ex.completionCode +
    48.           " Reason code " + ex.reasonCode);
    49.         }catch (IOException ex) {
    50.             // Was it a Java buffer space error?
    51.             System.out.println("An error occurred whilst writing to the message buffer: " + ex);
    52.         }catch(Exception ex){
    53.             ex.printStackTrace();
    54.         }
    55.     }
    56. }

  • 相关阅读:
    Go学习笔记1.3-变量的数据类型篇
    HR的职业规划
    2022VR高级研修班总结
    Node.js 20.6支持.env配置文件,加入C++垃圾回收函式库Oilpan
    VivadoAndTcl: synth_ip
    DataStream API(三)
    javaweb eclipse项目环境问题
    django|报错SQLite 3.8.3 or later is required的解决方案
    jQuery 的实现原理
    Spring核心问题回顾1:ioc容器创建的大致过程、bean的生命周期、解决循环依赖为什么需要三级缓存
  • 原文地址:https://blog.csdn.net/caryxp/article/details/132893377