在“websphere mq程序设计初探”一文中,讨论了从mq队列管理器的本地队列中放置和读出消息的程序,本文主要通过两台机器,搭建mq消息传输的环境,并编写测试程序进行测试。
第一、准备工作
准备2台win2000环境(xp也可),通过以太网连通。
机器a:代码为00000000,ip地址为:10.1.1.1
机器b:代码为88888888,ip地址为: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,采用默认设置。
第三、消息测试
在a、b机器上分别启动其发送方通道,正常情况通道状态应为“正在运行”。
通过如下测试程序进行测试,文件名为:mqtest.java,在机器a上进行运行(如在b上运行请读者自行适当修改)。
-------------------------------------------------------------------------------------------
import java.io.ioexception;
import java.util.hashtable;
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 mqsample{
//定义队列管理器和队列的名称
private static string qmname = "qm_00000000";
private static string qname = "rq_88888888";
private static mqqueuemanager qmgr;
private static hashtable properties = new hashtable();
public static void main(string args[]) {
try {
properties.put("hostname", "10.1.1.1");
properties.put("port", new integer(1414));
properties.put("channel", "dc.svrconn");
properties.put("ccsid", new integer(1381));
properties.put("transport","mqseries");
// create a connection to the queue manager
qmgr = new mqqueuemanager(qmname,properties);
// set up the options on the queue we wish to open...
int openoptions = 16;
// now specify the queue that we wish to open,
// and the open options...
mqqueue remoteq = qmgr.accessqueue(qname, openoptions);
// define a simple websphere mq message, and write some text in utf format..
mqmessage putmessage = new mqmessage();
putmessage.writeutf("test");
// specify the message options...
mqputmessageoptions pmo = new mqputmessageoptions();
// accept the defaults, same as mqpmo_default
// put the message on the queue
remoteq.put(putmessage,pmo);
system.out.println("message has been input into the remote queue");
// close the queue...
remoteq.close();
// disconnect from the queue manager
qmgr.disconnect();
}catch (mqexception ex) {
// if an error has occurred in the above, try to identify what went wrong
// was it a websphere mq error?
system.out.println("a websphere mq error occurred : completion code " + ex.completioncode +
" reason code " + ex.reasoncode);
}catch (ioexception ex) {
// was it a java buffer space error?
system.out.println("an error occurred whilst writing to the message buffer: " + ex);
}catch(exception ex){
ex.printstacktrace();
}
}
}
-------------------------------------------------------------------------------------------
运行程序后,请在b机器的本地队列lq_88888888中检查是否有消息存在,如果有说明测试成功。
读者可以自行编写把消息从对方的本地队列读取出来的程序。
如果读者对以上的内容有任何疑问,可以和我联系,qianh@cntmi.com
版权所有,严禁转载
参考资料:
1、《websphere mq system administration guide》third edition (may 2004),sc34-6068-02
2、《websphere mq using java》third edition (january 2004),sc34-6066-02
附件:mqtest.java(2k)
第一、准备工作
准备2台win2000环境(xp也可),通过以太网连通。
机器a:代码为00000000,ip地址为:10.1.1.1
机器b:代码为88888888,ip地址为: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,采用默认设置。
第三、消息测试
在a、b机器上分别启动其发送方通道,正常情况通道状态应为“正在运行”。
通过如下测试程序进行测试,文件名为:mqtest.java,在机器a上进行运行(如在b上运行请读者自行适当修改)。
-------------------------------------------------------------------------------------------
import java.io.ioexception;
import java.util.hashtable;
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 mqsample{
//定义队列管理器和队列的名称
private static string qmname = "qm_00000000";
private static string qname = "rq_88888888";
private static mqqueuemanager qmgr;
private static hashtable properties = new hashtable();
public static void main(string args[]) {
try {
properties.put("hostname", "10.1.1.1");
properties.put("port", new integer(1414));
properties.put("channel", "dc.svrconn");
properties.put("ccsid", new integer(1381));
properties.put("transport","mqseries");
// create a connection to the queue manager
qmgr = new mqqueuemanager(qmname,properties);
// set up the options on the queue we wish to open...
int openoptions = 16;
// now specify the queue that we wish to open,
// and the open options...
mqqueue remoteq = qmgr.accessqueue(qname, openoptions);
// define a simple websphere mq message, and write some text in utf format..
mqmessage putmessage = new mqmessage();
putmessage.writeutf("test");
// specify the message options...
mqputmessageoptions pmo = new mqputmessageoptions();
// accept the defaults, same as mqpmo_default
// put the message on the queue
remoteq.put(putmessage,pmo);
system.out.println("message has been input into the remote queue");
// close the queue...
remoteq.close();
// disconnect from the queue manager
qmgr.disconnect();
}catch (mqexception ex) {
// if an error has occurred in the above, try to identify what went wrong
// was it a websphere mq error?
system.out.println("a websphere mq error occurred : completion code " + ex.completioncode +
" reason code " + ex.reasoncode);
}catch (ioexception ex) {
// was it a java buffer space error?
system.out.println("an error occurred whilst writing to the message buffer: " + ex);
}catch(exception ex){
ex.printstacktrace();
}
}
}
-------------------------------------------------------------------------------------------
运行程序后,请在b机器的本地队列lq_88888888中检查是否有消息存在,如果有说明测试成功。
读者可以自行编写把消息从对方的本地队列读取出来的程序。
如果读者对以上的内容有任何疑问,可以和我联系,qianh@cntmi.com
版权所有,严禁转载
参考资料:
1、《websphere mq system administration guide》third edition (may 2004),sc34-6068-02
2、《websphere mq using java》third edition (january 2004),sc34-6066-02
附件:mqtest.java(2k)
闽公网安备 35060202000074号