我是 JMS 和 Websphere 服务器的新手,我正在尝试从我的 Java 代码访问在 Websphere Application Server 8 上配置的 JMS 队列。我无法准确理解应该为 Context.INITIAL_CONTEXT_FACTORY 设置什么值。它应该是类的完全限定类名还是特定于应用程序服务器的名称?
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
environment.put(Context.PROVIDER_URL, "iiop://localhost:9081");
将 Context.INITIAL_CONTEXT_FACTORY 的值设置为完全限定的类名(即 com.ms.test.Demo)时,我收到 NoInitialContextException。
PFB 我正在使用的代码 -
package com.jms.test;
import java.util.Hashtable;
import javax.jms.Queue;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Demo {
public static void main(String[] args) throws NamingException {
System.out.println("Start.....");
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.jms.test.Demo");
environment.put(Context.PROVIDER_URL, "iiop://localhost:9081");
//String pUrl = System.getProperty(Context.PROVIDER_URL);
//System.out.println("*******"+pUrl+"********");
InitialContext ctx = new InitialContext(environment);
Queue queue = (Queue) ctx.lookup("jms/TestQ111200");
System.out.println("*** Queue is *** "+queue.toString());
}}
我已使用以下链接中给出的步骤在 Websphere Application Server 中进行了 JMS 配置:http://pic.dhe.ibm.com/infocenter/iisinfsv/v8r1/index.jsp?topic=/com.ibm.swg.im.iis.infoservdir.user.doc/topics/t_isd_user_setting_up_jms_in_was.html http://pic.dhe.ibm.com/infocenter/iisinfsv/v8r1/index.jsp?topic=/com.ibm.swg.im.iis.infoservdir.user.doc/topics/t_isd_user_setting_up_jms_in_was.html
连接到 WebSphere 时,您始终使用以下类,而不是您自己的类。
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
需要正确连接WAS。
对于第二个属性,您需要提供引导端口而不是 http。通常是2809
,在中查找以下消息SystemOut.log
:
00000001 NameServerImp A NMSV0018I: Name server available on bootstrap port 2809.
您还需要特定的 jar 供您的客户端连接到 WAS JMS。看使用 WebSphere Application Server 安装和配置 JMS 瘦客户端 http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.iseries.doc/ae/tjj_jmsthcli_dev.html?lang=en
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)