没有 JNDI 的 JMS?
我们使用 Java 1.4 在 WebSphere 6.01 中运行 portlet。 我们想要将 JMS 消息发送到运行 Java 5(或者可能是 6,但它肯定比 1.4 更新)的 JBoss 5 队列。 尝试使用 JNDI 进行连接是行不通的,因为我们必须将 JBoss 客户端 jar 包含在 portlet 的类路径中,而且它们是 Java 1.5。 因此,当我尝试创建 InitialContext 时,出现不受支持的主要/次要错误。
我们可以不使用 JNDI 直接连接到 JBoss 吗? 或者有什么办法可以解决这个我想不到的问题?
We are running portlets in WebSphere 6.01, using Java 1.4. 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). 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. So I get an unsupported major/minor error when I try to create the InitialContext.
Can we connect straight to JBoss without using JNDI? Or is there some way to get around this issue I can't think of?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
听起来问题不在于 JNDI,而在于环境之间的类名冲突。
当您尝试实例化 JBOSS 客户端类时,您可以尝试自己进行类加载。 这样,您就可以从加载 Portlet 的类加载器中获得一个单独的类加载器。 只需确保您了解是否需要 父级优先或父级最后行为。 该页面上还有 调试类加载,它可以向您展示如何设置类加载器的类路径,以便您可以隔离 JBOSS 库并避免类名冲突。 它是一个很好的资源,甚至可以帮助您理解高级类加载问题。
It sounds like the problem isn't with JNDI but with the conflicting classnames between the environments.
You could try doing the classloading yourself when you try to instantiate the JBOSS client classes. That way you get a separate classloader from the one that loaded the Portlet. Just make sure you understand whether you need Parent-first or Parent-last behavior. 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. It is a good resource for understanding even advanced classloading issues.
事实上,使用 JNDI 是一种独立于 JMS 提供者的方法,因为您可以轻松地更改它。
但是,如果您对大多数提供商提供的设施来创建连接工厂和目的地没有任何疑问
In fact using JNDI is a way to be independant of the JMS provider, because you can easly change it.
But if you've got no problem with that most provider offer facilities to create a connection factory and destinations
我认为 JNDI 是您创建 JMS 连接工厂和目标(队列或主题)的唯一方法,这些是您的通信方式。
I think JNDI is the only way that you can create JMS connection factories and destinations (queue or topic), and these are your means of communication.
根据 JBoss 版本,您可以直接实例化所有 JMS 对象。
一个特定版本:
请参阅 http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/usermanual-2.0.0.beta1/html/using-jms.html
(第 5.5 节。不使用JNDI直接实例化JMS资源)
Depending on the JBoss version you can directly instantiate all the JMS objects.
One particular version:
see 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)
如果只是您的 JNDI 类需要 Java 5,而不是 JBoss 类,那么您可以执行此操作。 但是您必须设置对象的所有属性,并且这是特定于提供者的。 WebSphere MQ JMS 示例展示了如何使用 WMQ 执行此操作,您需要知道 JBoss 的属性和值名称才能编写等效代码。 下面是来自 WMQ JmsProducer.java 示例的代码片段:
另一方面,如果您的 JBoss 类需要 Java 1.5,那么您需要运行 Java 1.5 或更高版本。
If it's just your JNDI classes that prereq Java 5 and not the JBoss classes then you can do this. 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. Here is a code snippet from the WMQ JmsProducer.java sample:
On the other hand, if your JBoss classes prereq Java 1.5 then you need to run Java 1.5 or better.
即使您能够在不通过 JBoss 的 JNDI 的情况下连接到 JMS,您仍然需要包含 JBoss 客户端 JAR 才能使用 JMS。 JNDI 和 JMS 都是 API,您需要服务器实现该客户端 API 才能与服务器通信。
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. Both JNDI and JMS are APIs, and you need the server's implementation of that client API in order to talk to the server.