简体   繁体   English

没有JNDI的JMS?

[英]JMS without JNDI?

We are running portlets in WebSphere 6.01, using Java 1.4. 我们使用Java 1.4在WebSphere 6.01中运行portlet。 We want to send JMS messages to a JBoss 5 queue, running Java 5 (or maybe 6, but it's certainly newer than 1.4). 我们希望将JMS消息发送到JBoss 5队列,运行Java 5(或者可能是6,但它肯定比1.4更新)。 Trying to connect using JNDI is not working, since we have to include the JBoss client jars in the classpath of the portlet, and they are Java 1.5. 尝试使用JNDI进行连接是行不通的,因为我们必须在portlet的类路径中包含JBoss客户端jar,它们是Java 1.5。 So I get an unsupported major/minor error when I try to create the InitialContext. 因此,当我尝试创建InitialContext时,我得到一个不受支持的主要/次要错误。

Can we connect straight to JBoss without using JNDI? 我们可以在不使用JNDI的情况下直接连接到JBoss吗? Or is there some way to get around this issue I can't think of? 或者有什么方法可以解决这个我想不到的问题?

Even if you were able to connect to JMS without going through JBoss's JNDI, you would still need to include the JBoss client JAR in order to use JMS. 即使您能够在不通过JBoss的JNDI的情况下连接到JMS,您仍然需要包含JBoss客户端JAR才能使用JMS。 Both JNDI and JMS are APIs, and you need the server's implementation of that client API in order to talk to the server. JNDI和JMS都是API,您需要服务器实现该客户端API才能与服务器通信。

If it's just your JNDI classes that prereq Java 5 and not the JBoss classes then you can do this. 如果它只是你的JNDI类,它们是先前的Java 5而不是JBoss类,那么你就可以做到这一点。 But you would have to set all of the properties of the objects and that is provider-specific. 但是您必须设置对象的所有属性,这是特定于提供者的。 The WebSphere MQ JMS samples show how to do this with WMQ and you would need to know the property and value names for JBoss to make the equivalent code. WebSphere MQ JMS示例演示了如何使用WMQ执行此操作,您需要知道JBoss的属性和值名称以生成等效代码。 Here is a code snippet from the WMQ JmsProducer.java sample: 以下是WMQ JmsProducer.java示例的代码片段:

  JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
  JmsConnectionFactory cf = ff.createConnectionFactory();

  // Set the properties
  cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, host);
  cf.setIntProperty(WMQConstants.WMQ_PORT, port);
  cf.setStringProperty(WMQConstants.WMQ_CHANNEL, channel);
  cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
  cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, queueManagerName);

  // Create JMS objects
  connection = cf.createConnection();
  session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  if (isTopic) {
    destination = session.createTopic(destinationName);
  }
  else {
    destination = session.createQueue(destinationName);
  }
  producer = session.createProducer(destination);

On the other hand, if your JBoss classes prereq Java 1.5 then you need to run Java 1.5 or better. 另一方面,如果您的JBoss类先于Java 1.5,那么您需要运行Java 1.5或更高版本。

Depending on the JBoss version you can directly instantiate all the JMS objects. 根据JBoss版本,您可以直接实例化所有JMS对象。

One particular version: see http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/usermanual-2.0.0.beta1/html/using-jms.html 一个特定版本:请参阅http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/usermanual-2.0.0.beta1/html/using-jms.html

(Section 5.5. Directly instantiating JMS Resources without using JNDI) (第5.5节。不使用JNDI直接实例化JMS资源)

我认为JNDI是您创建JMS连接工厂和目标(队列或主题)的唯一方法,这些是您的通信方式。

In fact using JNDI is a way to be independant of the JMS provider, because you can easly change it. 事实上,使用JNDI是一种独立于JMS提供程序的方法,因为您可以轻松地更改它。 But if you've got no problem with that most provider offer facilities to create a connection factory and destinations 但是,如果您对大多数提供商提供设施创建连接工厂和目的地没有任何问题

It sounds like the problem isn't with JNDI but with the conflicting classnames between the environments. 听起来问题不在于JNDI,而在环境之间存在冲突的类名。

You could try doing the classloading yourself when you try to instantiate the JBOSS client classes. 当您尝试实例化JBOSS客户端类时,您可以尝试自己进行类加载。 That way you get a separate classloader from the one that loaded the Portlet. 这样,您就可以从加载Portlet的类加载器中获得单独的类加载器。 Just make sure you understand whether you need Parent-first or Parent-last behavior . 只需确保您了解是否需要Parent-first或Parent-last行为 Also on that page is debugging classloading which can show you how to set the Classpath for the classloader so you can isolate the JBOSS libraries and avoid classname collisions. 此页面上还有调试类加载 ,它可以向您展示如何设置类加载器的类路径,以便您可以隔离JBOSS库并避免类名冲突。 It is a good resource for understanding even advanced classloading issues . 它是理解甚至高级类加载问题的好资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM