問(wèn)題描述
我有一個(gè)通用的獨(dú)立 JMS 應(yīng)用程序,它與以下 JMS 提供程序 WebSphere、HornetQ 和 ActiveMq 一起使用.我將 Context.INITIAL_CONTEXT_FACTORY 和 Context.PROVIDER_URL 作為參數(shù)傳遞給我的應(yīng)用程序,并通過(guò)執(zhí)行類(lèi)似的操作從它們中創(chuàng)建命名上下文
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);
并使用此上下文進(jìn)行對(duì)象查找.
And use this context for object lookup.
我了解 RabbitMQ 不是 JMS 提供者,因此它沒(méi)有 InitialContext 類(lèi)或提供者 URL,但它提供了一個(gè) JMS 客戶(hù)端,它是符合 JMS 規(guī)范的 Java 客戶(hù)端的抽象.RabbitMQ 的 JMS 客戶(hù)端 documentation 有一個(gè)在 JNDI 中將對(duì)象定義為資源配置作為 Web 應(yīng)用程序的一部分,但我完全不知道如何為我的獨(dú)立應(yīng)用程序執(zhí)行類(lèi)似的操作,該應(yīng)用程序使用 JMS 客戶(hù)端的依賴(lài)項(xiàng)創(chuàng)建基于 JNDI 提供程序的命名上下文,或者從可用的依賴(lài)項(xiàng)中創(chuàng)建 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.
那么有人可以說(shuō)明如何做到這一點(diǎn)嗎?希望我的問(wèn)題很清楚.
So can someone throw some light on how this can be done? Hope my question is clear.
推薦答案
對(duì)于遇到這個(gè)異常的人
Caused by: javax.naming.NamingException: Unknown class [com.rabbitmq.jms.admin.RMQConnectionFactory]
即使在遵循@Ualter Jr. 的回答之后也是因?yàn)?.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
當(dāng)我再次遇到這個(gè)異常時(shí),我剛剛打開(kāi)了這個(gè) class 發(fā)現(xiàn)它需要以下類(lèi)名
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
*
*/
更正這些條目將使現(xiàn)有/新的 JMS 應(yīng)用程序能夠與 RabbitMQ 一起使用.
Correcting these entries would enable existing/new JMS applications to work with RabbitMQ.
這篇關(guān)于如何使用 RabbitMQ JMS 客戶(hù)端從現(xiàn)有 JMS 應(yīng)用程序連接到 RabbitMQ?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!