[rabbitmq-discuss] JNDI / .bindings with RabbitMQ JMS Client?

scguy npetrace at gmail.com
Sun May 18 00:40:19 BST 2014


Question...I'm trying to use the RabbitMQ JMS client with an existing JMS
client application.  

I have written a sample java program, and am referencing a .bindings file
(below).  I have the following plugins installed on my RabbitMQ server (this
is on Windows):

C:\dev\rabbitmq330\rabbit\sbin>rabbitmq-plugins list
[e] amqp_client                       3.3.0
[ ] cowboy                            0.5.0-rmq3.3.0-git4b93c2d
[ ] eldap                             3.3.0-gite309de4
[e] mochiweb                          2.7.0-rmq3.3.0-git680dba8
[ ] rabbitmq_amqp1_0                  3.3.0
[ ] rabbitmq_auth_backend_ldap        3.3.0
[ ] rabbitmq_auth_mechanism_ssl       3.3.0
[ ] rabbitmq_consistent_hash_exchange 3.3.0
[ ] rabbitmq_federation               3.3.0
[ ] rabbitmq_federation_management    3.3.0
[E] rabbitmq_jms_topic_exchange       1.2.0-rmq3.3.0
[e] rabbitmq_jsonrpc                  3.3.x-24fb08eb
[E] rabbitmq_jsonrpc_channel          3.3.x-40bdb08c
[E] rabbitmq_management               3.3.0
[e] rabbitmq_management_agent         3.3.0
[E] rabbitmq_management_visualiser    3.3.0
[ ] rabbitmq_mqtt                     3.3.0
[ ] rabbitmq_shovel                   3.3.0
[ ] rabbitmq_shovel_management        3.3.0
[E] rabbitmq_stomp                    3.3.0
[ ] rabbitmq_tracing                  3.3.0
[e] rabbitmq_web_dispatch             3.3.0
[ ] rabbitmq_web_stomp                3.3.0
[ ] rabbitmq_web_stomp_examples       3.3.0
[e] rfc4627_jsonrpc                   3.3.x-git5e67120
[ ] sockjs                            0.3.4-rmq3.3.0-git3132eb9
[e] webmachine                        1.10.3-rmq3.3.0-gite9359c7

I have the following on my classpath:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_25"/>
    <classpathentry kind="lib"
path="C:/dev/rabbitmq330/jms-package1.2.0/dependencies/amqp-client-3.3.0.jar"/>
    <classpathentry kind="lib"
path="C:/dev/rabbitmq330/jms-package1.2.0/dependencies/fscontext.jar"/>
    <classpathentry kind="lib"
path="C:/dev/rabbitmq330/jms-package1.2.0/dependencies/geronimo-jms_1.1_spec-1.1.1.jar"/>
    <classpathentry kind="lib"
path="C:/dev/rabbitmq330/jms-package1.2.0/dependencies/providerutil.jar"/>
    <classpathentry kind="lib"
path="C:/dev/rabbitmq330/jms-package1.2.0/dependencies/slf4j-api-1.7.5.jar"/>
    <classpathentry kind="lib"
path="C:/dev/rabbitmq330/jms-package1.2.0/rabbitmq-jms-1.2.0.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

However, when I attempt to run my java program, I get the following error. 
This is where I am stuck...I'm not sure what is wrong...as the mentioned
class is in the rabbitmq-jms-1.2.0.jar file, and that jar is on my
classpath.  Any thoughts on what I have done wrong?  I need to use the JMS
client...otherwise I would just use the AMQP library.

Code snippet (the error occurs on the connection factory lookup):

Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:/rabbitmq"); // directory where the
.bindings file is located
      
mContext = new InitialContext(env);

ConnectionFactory connectionFactory = (ConnectionFactory)
mContext.lookup("ConnectionFactory");
mConnection = connectionFactory.createConnection();
mConnection.start();      

.bindings file:

ConnectionFactory/ClassName=com.rabbitmq.jms.admin.RMQConnectionFactory
ConnectionFactory/FactoryName=com.rabbitmq.jms.admin.RMQObjectFactory
 
ConnectionFactory/RefAddr/0/Content=jms/ConnectionFactory
ConnectionFactory/RefAddr/0/Type=name
ConnectionFactory/RefAddr/0/Encoding=String
 
ConnectionFactory/RefAddr/1/Content=javax.jms.ConnectionFactory
ConnectionFactory/RefAddr/1/Type=type
ConnectionFactory/RefAddr/1/Encoding=String
 
ConnectionFactory/RefAddr/2/Content=com.rabbitmq.jms.admin.RMQObjectFactory
ConnectionFactory/RefAddr/2/Type=factory
ConnectionFactory/RefAddr/2/Encoding=String
 
# Change this line accordingly if the broker is not at localhost
ConnectionFactory/RefAddr/3/Content=localhost
ConnectionFactory/RefAddr/3/Type=host
ConnectionFactory/RefAddr/3/Encoding=String

#Destinations
TempQueue/ClassName=com.rabbitmq.jms.admin.RMQDestination
TempQueue/FactoryName=com.rabbitmq.jms.admin.RMQObjectFactory
 
TempQueue/RefAddr/0/Content=jms/Queue
TempQueue/RefAddr/0/Type=name
TempQueue/RefAddr/0/Encoding=String
 
TempQueue/RefAddr/1/Content=javax.jms.Queue
TempQueue/RefAddr/1/Type=type
TempQueue/RefAddr/1/Encoding=String
 
TempQueue/RefAddr/2/Content=com.rabbitmq.jms.admin.RMQObjectFactory
TempQueue/RefAddr/2/Type=factory
TempQueue/RefAddr/2/Encoding=String
 
TempQueue/RefAddr/3/Content=TempQueue
TempQueue/RefAddr/3/Type=destinationName
TempQueue/RefAddr/3/Encoding=String

C:\TEMP>java -jar rabbitmqjms.jar
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: javax.naming.NamingException: Unknown class
[com.rabbitmq.jms.admin.RMQConnectionFactory]
        at
com.rabbitmq.jms.admin.RMQObjectFactory.getObjectInstance(RMQObjectFactory.java:132)
        at
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
        at com.sun.jndi.fscontext.RefFSContext.lookup(RefFSContext.java:146)
        at com.sun.jndi.fscontext.FSContext.lookup(FSContext.java:127)
        at javax.naming.InitialContext.lookup(InitialContext.java:411)
        at rabbitMQJMSTestDriver.<init>(rabbitMQJMSTestDriver.java:31)
        at rabbitMQJMSTestDriver.main(rabbitMQJMSTestDriver.java:107)
        ... 5 more



--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/JNDI-bindings-with-RabbitMQ-JMS-Client-tp35631.html
Sent from the RabbitMQ mailing list archive at Nabble.com.


More information about the rabbitmq-discuss mailing list