如何使用 RabbitMQ JMS 客户端从现有 JMS 应用程序连接到 RabbitMQ? [英] How to connect to RabbitMQ using RabbitMQ JMS client from an existing JMS application?

查看:39
本文介绍了如何使用 RabbitMQ JMS 客户端从现有 JMS 应用程序连接到 RabbitMQ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通用的独立 JMS 应用程序,它与以下 JMS 提供程序 WebSphere、HornetQ 和 ActiveMq 一起使用.我将 Context.INITIAL_CONTEXT_FACTORY 和 Context.PROVIDER_URL 作为参数传递给我的应用程序,并通过执行类似的操作从它们中创建命名上下文

I have a generic standalone JMS application which works with following JMS providers WebSphere, HornetQ and ActiveMq. I pass Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL as parameters to my application and create a naming context out of them by doing something like this

Properties environmentParameters = new Properties();
environmentParameters.put(Context.INITIAL_CONTEXT_FACTORY, property.context);
environmentParameters.put(Context.PROVIDER_URL, property.provider);
namingContext = new InitialContext(environmentParameters);

并使用此上下文进行对象查找.

And use this context for object lookup.

我了解 RabbitMQ 不是 JMS 提供者,因此它没有 InitialContext 类或提供者 URL,但它提供了一个 JMS 客户端,它是符合 JMS 规范的 Java 客户端的抽象.RabbitMQ 的 JMS 客户端 documentation 有一个在 JNDI 中将对象定义为资源配置作为 Web 应用程序的一部分,但我完全不知道如何为我的独立应用程序执行类似的操作,该应用程序使用 JMS 客户端的依赖项创建基于 JNDI 提供程序的命名上下文,或者从可用的依赖项中创建 InitialContext.

I understand RabbitMQ isn't a JMS provider so it doesn't have an InitialContext class or a Provider URL but it provides a JMS Client which is an abstraction of its Java client conforming to JMS specification. RabbitMQ's JMS client documentation has an example of defining objects in JNDI as a resource configuration as part of a web application but I quite couldn't figure out how to do something similar for my standalone application which creates a naming context based on JNDI provider using JMS client's dependencies or to create an InitialContext out of the available dependencies.

那么有人可以说明如何做到这一点吗?希望我的问题很清楚.

So can someone throw some light on how this can be done? Hope my question is clear.

推荐答案

对于遇到这个异常的人

Caused by: javax.naming.NamingException: Unknown class [com.rabbitmq.jms.admin.RMQConnectionFactory]

即使在遵循@Ualter Jr. 的回答之后也是因为 .bindings 文件中的条目不正确.

even after following @Ualter Jr.'s answer is because of incorrect entries in the .bindings file.

我更正了 .bindings 文件中的以下 2 行

I corrected the following 2 lines in .bindings file

ConnectionFactory/ClassName=com.rabbitmq.jms.admin.RMQConnectionFactory --->
ConnectionFactory/ClassName=javax.jms.ConnectionFactory

YourQueueName/ClassName=com.rabbitmq.jms.admin.RMQDestination --->
StriimQueue/ClassName=javax.jms.Queue

当我再次遇到这个异常时,我刚刚打开了这个 class 发现它需要以下类名

When I hit this exception again I just opened this class and found that it expects the following classnames

      /*
     * Valid class names are:
     * javax.jms.ConnectionFactory
     * javax.jms.QueueConnectionFactory
     * javax.jms.TopicConnectionFactory
     * javax.jms.Topic
     * javax.jms.Queue
     *
     */

更正这些条目将使现有/新的 JMS 应用程序能够与 RabbitMQ 一起使用.

Correcting these entries would enable existing/new JMS applications to work with RabbitMQ.

这篇关于如何使用 RabbitMQ JMS 客户端从现有 JMS 应用程序连接到 RabbitMQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆