JNDI / .bindings with RabbitMQ JMS Client?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

JNDI / .bindings with RabbitMQ JMS Client?

scguy
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
Reply | Threaded
Open this post in threaded view
|

Re: JNDI / .bindings with RabbitMQ JMS Client?

mc717990
Off hand, it appears that you're missing some libraries.  I'm not sure what rabbitmqjms.jar is as I've not looked at the JMS stuff personally but you're missing whatever library provides "com.rabbitmq.jms.admin.RMQConnectionFactory".  What's interesting is that it's in the same class structure as the instance loader (the RMQObjectFactory) - so I'd guess there could be an issue someplace with URL class loading or similar.  If the ObjectFactory and ConnectionFactory are with-in the same jar you shouldn't be getting this, but if they're in a different jar file you'll very likely have issues.  Java doesn't support loading JAR files from with-in a JAR file for dependencies.

Jason


On Sat, May 17, 2014 at 6:40 PM, scguy <[hidden email]> wrote:
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.
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss



--
Jason McIntosh
https://github.com/jasonmcintosh/
573-424-7612

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: JNDI / .bindings with RabbitMQ JMS Client?

scguy
Yes...I had mentioned in my original post that com.rabbitmq.jms.admin.RMQConnectionFactory is located in rabbitmq-jms-1.2.0.jar, which is on my classpath (same jar as RMQObjectFactory).  Do I need to configure something else so that the class is found?
Reply | Threaded
Open this post in threaded view
|

Re: JNDI / .bindings with RabbitMQ JMS Client?

scguy
Looks like this might be version related?  I "downgraded" to rabbitmq-server 3.1.5 and rabbitmq-jms-1.0.5 and everything worked.  Further suggestions or comments on this are appreciated.
Reply | Threaded
Open this post in threaded view
|

Re: JNDI / .bindings with RabbitMQ JMS Client?

Steve Powell-2
Hi, sorry I didn’t see this before today.

It looks to me as though the JNDI server is populated with an older com.rabbitmq.jms.admin.RMQConnectionFactory version.  In RJMS 1.1.0 some extensions were made to the JNDI for connection factories to allow for ssl connections and the AMQP interoperability feature.  This meant that previously serialised RMQConnectionFactory objects (for example in a JNDI server store) are not de-serializable under later versions of RJMS.

The solution to your problem would be to re-populate the JNDI server with RMQConnectionFactory objects created with the same level of RJMS as the application is expecting.

Please come back to me, if this doesn’t’ fix it.

Steve Powell  [Cell: +44-7815-838-558]
    Good design [] is as little design as possible.    Dieter Rams

On 20 May 2014, at 07:10, scguy <[hidden email]> wrote:

Looks like this might be version related?  I "downgraded" to rabbitmq-server
3.1.5 and rabbitmq-jms-1.0.5 and everything worked.  Further suggestions or
comments on this are appreciated.



--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/JNDI-bindings-with-RabbitMQ-JMS-Client-tp35631p35678.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: JNDI / .bindings with RabbitMQ JMS Client?

scguy
No problem...thanks for the response!  In this case, I am not using a separate JNDI server; the application simply uses a .bindings file and the com.sun.jndi.fscontext.RefFSContextFactory context factory.  Would the entries in my .bindings file need to change for the later version of RabbitMQ/RJMS?
Reply | Threaded
Open this post in threaded view
|

Re: JNDI / .bindings with RabbitMQ JMS Client?

mc717990
 Based upon the class path system you listed, it appears that you're running from with-in Eclipse?  If so, be very careful that eclipse doesn't somehow add onto your classpath.  Just a suggestion.  First, run your app outside of Eclipse.  Then run jconsole, connect to your local process that's running, and go to the VM Summary tab.  Take a look at the Library Path/Boot classpath.  Since you're using a FsContext to load JNDI through a file provider, I'd guess an issue with different versions of the java library due to a different version of the jar somehow making it onto your class path. 
Jason






On Tue, May 20, 2014 at 9:54 AM, scguy <[hidden email]> wrote:
No problem...thanks for the response!  In this case, I am not using a
separate JNDI server; the application simply uses a .bindings file and the
com.sun.jndi.fscontext.RefFSContextFactory context factory.  Would the
entries in my .bindings file need to change for the later version of
RabbitMQ/RJMS?



--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/JNDI-bindings-with-RabbitMQ-JMS-Client-tp35631p35704.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss



--
Jason McIntosh
https://github.com/jasonmcintosh/
573-424-7612

_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|

Re: JNDI / .bindings with RabbitMQ JMS Client?

Steve Powell-2
In reply to this post by scguy
Hmm, I’m not too familiar with this path, but what Jason recommends would  help you to check that the RefFSContextFactory is using the same classes as we are. The attributes are additive, so old bindings should still work.

It is possible that the Resource interface parts of the RMQConnectionFactory class aren’t working correctly, but again it was merely an extension to the previous version.

What would we need to reproduce your JNDI setup?
Steve Powell  [Cell: +44-7815-838-558]
    Good design [] is as little design as possible.    Dieter Rams

On 20 May 2014, at 15:54, scguy <[hidden email]> wrote:

No problem...thanks for the response!  In this case, I am not using a
separate JNDI server; the application simply uses a .bindings file and the
com.sun.jndi.fscontext.RefFSContextFactory context factory.  Would the
entries in my .bindings file need to change for the later version of
RabbitMQ/RJMS?



--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/JNDI-bindings-with-RabbitMQ-JMS-Client-tp35631p35704.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


_______________________________________________
rabbitmq-discuss mailing list
[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss