CSDN博客

img tdg2002

MQ和WEBSPHERE整合

发表于2003/9/15 23:46:00  918人阅读

整合MQWEBSPHERE

参考文章:http://www2.tw.ibm.com/developerWorks/tutorial/content/20021207.html

环境:

Win2000 SP4WebSphere4 AESMQ5.2.1

本文假设你已正确安装webspheremq5.2.1并且在mq上定义下列队列管理器,在dos下切换到C:/Program Files/IBM/MQSeries/bin下,键入:

crtmqm -q QM_TEST

strmqm QM_TEST

runmqsc QM_TEST

DEFINE QL(DEADQ_TEST) DEFPSIST(YES) REPLACE

ALTER QMGR DEADQ(DEADQ_TEST)

DEFINE PROCESS(P_TEST) APPLTYPE(WINDOWSNT) APPLICID('runmqchl -c SDR_TEST -m QM_TEST ') REPLACE

DEFINE QL(QT_TEST) USAGE(XMITQ) DEFPSIST(YES) INITQ(SYSTEM.CHANNEL.INITQ) PROCESS(P_TEST) REPLACE

DEFINE QREMOTE(QR_TEST) RNAME(Q_TEST1) RQMNAME(QM_TEST1) XMITQ(QT_TEST) REPLACE

DEFINE CHANNEL(SDR_TEST) CHLTYPE(SDR) CONNAME('192.168.0.28 (2001)') XMITQ(QT_TEST) REPLACE

DEFINE CHANNEL(SDR_TEST1) CHLTYPE(RCVR) REPLACE

DEFINE CHANNEL(S_TEST) CHLTYPE(SVRCONN) REPLACE

runmqlsr -t tcp -p 2001 -m QM_TEST

start chl(SDR_TEST)

(上述语句最好手工键入,因为有的语句分成了两行。-:)

需要的运行环境包的下载地址:

点对点模式(ma_88):

http://www-3.ibm.com/software/integration/support/supportpacs/individual/ma88.html

发布/订阅模式(ma_0c):
http://www-3.ibm.com/software/integration/support/supportpacs/individual/ma0c.html

下载上述包并安装。具体系统采取点对点还是发布/订阅模式则自行选择安装。或者两种都安装。切记安装后马上重启并且不要按默认路径把包安装到C:/Program Files下。因为这样会导致CLASSPATH长度超过255,在运行时会报找不到类的错误。

约定:

在本文中%MQ_JAVA_INSTALL_PATH%C:/MQSeries

        WAS_HOME%E:/WebSphere/AppServer

1

修改 %MQ_JAVA_INSTALL_PATH%/binJMSAdmin.config中的,在

INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory的前面加上#

下面另起一行:INITIAL_CONTEXT_FACTORY=com.ibm.ejs.ns.jndi.CNInitialContextFactory

PROVIDER_URL=ldap://polaris/o=ibm_us,c=us的前面加上#

下面另起一行:PROVIDER_URL=iiop://localhost/

2

修改JMSAdmin.bat:

@echo on

rem ----------------------------------------------

rem  IBM MQSeries JMS Admin Tool Execution Script

rem

rem  Note that the properties passed to the java

rem  program are defaults, and should be edited

rem  to suit your installation if necessary

rem ----------------------------------------------

 

java  -DMQJMS_LOG_DIR=C:/MQSeries/log

-DMQJMS_TRACE_DIR=C:/MQSeries/trace

-DMQJMS_INSTALL_PATH=C:/MQSeries

-Dserver.root=E:/WebSphere/AppServer com.ibm.mq.jms.admin.JMSAdmin %1 %2 %3 %4 %5

pause

3.

新增一文本文件:

@echo on

@rem Java runtime

 set JAVA_HOME=%WAS_HOME%/java/bin

@rem MQ JMS

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib/com.ibm.mq.jar

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib/com.ibm.mqjms.jar

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib/jms.jar

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib/com.ibm.mq.iiop.jar

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib/com.ibm.mqbind.jar

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib/jndi.jar

 set MQ=%MQ%;E:/WebSphere/AppServer/java/jre/lib/rt.jar

@rem needed if using LDAP or file system for JNDI

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib/ldap.jar

@rem needed if using the file system for JNDI

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib/fscontext.jar

 set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%/lib/providerutil.jar

@rem needed to use WebSphere name service for JNDI

 set WebSphereCP=%WAS_HOME%/lib/ns.jar

 set CLASSPATH=%MQ%;%WebSphereCP%;%CLASSPATH%

 set PATH=%JAVA_HOME%;%MQ_JAVA_INSTALL_PATH%/lib;%PATH%;

把这个文本文件另存为setenv.bat,保存到%MQ_JAVA_INSTALL_PATH%/bin

上述命令是把%MQ_JAVA_INSTALL_PATH%/lib/下的所有.jar文件和%WAS_HOME%/ java/jre/lib/rt.jar还有%WAS_HOME%/lib/ns.jar加到classpath中,把java_home变量设为%WAS_HOME%/java/bin.

运行cmd,切换到%MQ_JAVA_INSTALL_PATH%/bin下,运行setenv。检查类路径是否正确。

运行jmsadmin -t -v -cfg jmsadmin.config

 

如果看到上述提示则配置正确,否则请根据提示信息操作。多数是找不到包,请自行修改setenv.bat

4

定義QueueConnectionFactory -> QCF

键入:

define QCF(test) QMANAGER(QM_TEST)

定義Queue

键入:define Q(test1) QUEUE(Q_TEST) QMANAGER(QM_TEST)

键入:end

5

Windows 2000path系統变量中加入%MQ_JAVA_INSTALL_PATH%/lib的路径

运行开始->程序->IBM WebSphere->Application Server v4.0AES->Start Application Server.

ie地址栏键入http://localhost:9090/admin/ 在用户标识中随便键入一个名字如test。点击左边树的节点->你的节点名称->应用程序服务器->Default Server>进程定义->jvm设置

在类路径中加入:%MQ_JAVA_INSTALL_PATH%/lib;
                    %MQ_JAVA_INSTALL_PATH%/lib/com.ibm.mq.jar;
                    %MQ_JAVA_INSTALL_PATH%/lib/com.ibm.mqjms.jar;
                    %WAS_HOME%/lib/j2ee.jar

点“确定”,重启Default Server.

6.

ie地址栏键入http://localhost:9090/admin/,在用户标识中键入test,

在服务器类路径中输入 %MQ_JAVA_INSTALL_PATH%/lib;
 %MQ_JAVA_INSTALL_PATH%/lib/com.ibm.mq.jar;

%MQ_JAVA_INSTALL_PATH%/lib/com.ibm.mqjms.jar;
%MQ_JAVA_INSTALL_PATH%/lib/fscontext.jar;

%MQ_JAVA_INSTALL_PATH%/lib/providerutil.jar

在外部初始上下文工厂中输入:com.ibm.ejs.ns.jndi.CNInitialContextFactory点击“确定”

jms供应商->IBM MQSeries (Local WebSphere Naming Context)->JMS连接工厂,在名称中填入test,在外部jndi名中填入test,在连接类型中选择队列,点击确定”.

jms供应商->IBM MQSeries (Local WebSphere Naming Context)->JMS目标,在名称和外部jndi名中填入test1,在目标类型中选择队列.点击确定”.

编写测试程序:

import javax.naming.*;

import com.ibm.jms.*;

import com.ibm.mq.jms.*;

import javax.jms.*;

import com.ibm.rmi.iiop.*;

import java.util.*;

import com.ibm.ejs.ns.jndi.*;

public class TestConnection {

  public TestConnection() {

  }

  public static void main(String[] args) {

    TestConnection testConnection1 = new TestConnection();

    try{

      Properties props=new Properties();

      props.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");

      props.put(Context.PROVIDER_URL,"iiop://localhost/");

      props.put(Context.SECURITY_AUTHENTICATION,"none");

      InitialContext ctx = new InitialContext(props);

      QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("test");

      QueueConnection qc = qcf.createQueueConnection();

      QueueSession session = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      Queue q = (Queue) ctx.lookup("test1");

      QueueSender sender = session.createSender(q);

      TextMessage tm=session.createTextMessage();

      tm.setText("hahaha!");

      sender.send(tm);

    }catch(javax.naming.NamingException ne){

      ne.printStackTrace();

    }catch(javax.jms.JMSException jmse){

      jmse.printStackTrace();

    }

  }

 

}

至此点对点的设置结束。至于发布/订阅模式则稍后再发。

有不对的地方请指教。

0 0

相关博文

我的热门文章

img
取 消
img