問題描述
我有一個通用的獨立 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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!