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

查看:1019
本文介绍了如何使用现有JMS应用程序中的RabbitMQ 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类或Provider URL,但它提供了一个JMS Client,它是Java的抽象客户端符合JMS规范。 RabbitMQ的JMS客户端文档中有一个将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文件中更正了以下两行

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

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

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.

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

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