mq软件提供一个java软件包,里面有jms类库,和一套mq的类库。不熟悉mqi编程方法的程序员可以用jms,比较熟悉mqi编程方法的程序则可以用mq类库来编程。下面的小程序是使用java实现从队列管理器qm_server中的队列initq写入或读出消息。
package transfer;
import com.ibm.mq.*;
public class sendmsg1
{
private mqqueuemanager qmgr;//定义一个队列管理器变量
public static void main(string args[])
{
new sendmsg1();
}
public sendmsg1()
{
mqenvironment.hostname="192.168.1.18";//本地ip
mqenvironment.channel="channel1";//用来通信的通道
mqenvironment.ccsid =1381;
try{
qmgr=new mqqueuemanager("qm_server");//队列管理器名称
int openoptions=mqc.mqoo_input_as_q_defmqc.mqoo_outputmqc.mqoo_inquire;
mqqueue queue=qmgr.accessqueue("initq",openoptions,null,null,null);
//建立连接
mqmessage hello=new mqmessage();//要写入队列的消息
try{
hello.format=mqc.mqfmt_string ;
hello.characterset=1381 ;
hello.writestring("这是测试!");
}
catch(java.io.ioexception ex)
{}finally{};
mqputmessageoptions pmo=new mqputmessageoptions();
for (int i=1;i<=5;i++)//将消息依次写入队列
{
hello.expiry=-1; //设置消息用不过期
queue.put(hello);//将消息放入队列
}
queue.close() ;//关闭队列
qmgr.disconnect() ; //断开连接
}
catch(exception ex)
{}
finally{};
}
}Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器