7 Replies Latest reply on Mar 14, 2014 12:47 PM by jbertram

    Question on JNDI names

    tbronzan

      So I was looking at the following document to try and resolve some naming oddities:

       

      Messaging configuration - WildFly 8 - Project Documentation Editor

       

      Basically I have some jms topics that need to be referenced from an EAR deployed on WildFly or a standalone client.  For example, consider the topic with the following entries:

       

      java:jboss/jms/SomeTopic

      java:jboss/exported/jms/SomeTopic

       

      When I do a local lookup from within the EAR I need to use java:jboss/jms/SomeTopic.  When I do a look up from a remote client, I simply need to put in jms/SomeTopic.  Is there no way to do a local lookup using jms/SomeTopic?  The documentation seems to be incorrect in that is says you can create an entry called jms/SomeTopic but the web administration says that jndi names are required to start with java:/ or java:jboss/.  The reason I'm asking is that some of the classes that do lookups to the topics are in common libs and the code doing the lookup needs to know whether or not it's being run inside the EAR or in a standalone client to determine which name it needs to use.  At the end of the day it's not a huge deal, but I'd like to try an understand why things work the way they do.

       

      Thanks.

        • 1. Re: Question on JNDI names
          emmartins

          The absolute names such as java:jboss/exported/jms/SomeTopic do not work in the remote client?

          • 2. Re: Question on JNDI names
            tbronzan

            java:jboss/exported/jms/SomeTopic does not work from the remote client, which is fine because the linked document states that java:jboss/exported does not need to be included in the name.  My issue is that local lookups require java:jboss/, which is inconsistent with how remote lookups work.  The result is I end up with code that looks like:

             

            String topic = isRemote ? "jms/SomeTopic" : "java:jboss/jms/SomeTopic";

             

            When really I should be able to simply use jms/SomeTopic for both local and remote lookups.  If it was just one or two topics it wouldn't be a big deal, but there's many topics that can be accessed locally and remotely.

            • 3. Re: Question on JNDI names
              emmartins

              The real JNDI names are the absolute ones, and the standard JNDI lookup code does not supports non absolute lookups from the initial context. But some frameworks and APIs allows non absolute names, considering these are being used in a specific context, for instance @Resource considers non absolute names are relative to java:comp/env.

               

              I'm not familiar with JNDI lookups not supporting absolute names, can you please share the lookup code being used in EAR and in client?

              • 4. Re: Question on JNDI names
                emmartins

                I looked at the link you shared, see nothing related, wrong URL?

                • 5. Re: Question on JNDI names
                  jbertram

                  Doesn't the documentation you cited (i.e. https://docs.jboss.org/author/display/WFLY8/Messaging+configuration) already answer your question?  Given a queue configured like so:

                   

                          <jms-queue name="testQueue">
                              <entry name="jms/queue/test"/>
                              <entry name="java:jboss/exported/jms/queue/test"/>
                          </jms-queue>
                  

                   

                  The documentation states:

                  Each entry refers to a JNDI name of the queue or topic.  Keep in mind that any jms-queue or jms-topic which needs to be accessed by a remote client needs to have an entry in the "java:jboss/exported" namespace.  As with connection factories, if a jms-queue or jms-topic has an entry bound in the "java:jboss/exported" namespace a remote client would look it up using the text after "java:jboss/exported".  For example, the following jms-queue "testQueue" is bound to "java:jboss/exported/jms/queue/test" which means a remote client would look-up this jms-queue using "jms/queue/test".  A local client could look it up using "java:jboss/exported/jms/queue/test", "java:jms/queue/test", or more simply "jms/queue/test"...

                   

                  So, based on this both a local and remote client could use "jms/queue/test" in their lookup.  Have you tried this and found that it doesn't work as advertised?

                  • 6. Re: Re: Question on JNDI names
                    tbronzan

                    Yes, that is what I am trying to say.  If I do a remote lookup I can use "jms/queue/test" but if I do a local lookup I have to use "java:jms/queue/test".  If I try "jms/queue/test' from within the ear file I get a naming not found exception saying that it cannot find "jms/queue/test".  The other issue is that I cannot create a destination with the name "jms/queue/test".  The web administration in WildFly says that JNDI names must begin with either java:/ or java:jboss/.  That probably explains why "jms/queue/test" does not work.  This is how I have to create destinations:

                     

                    <jms-queue name="testQueue">
                         <entry name="java:jboss/jms/queue/test"/>
                         <entry name="java:jboss/exported/jms/queue/test"/>
                    </jms-queue>
                    

                        

                    As I've stated before, to do a remote lookup I can use just jms/queue/test.  For a local lookup I have to use java:jboss/jms/queue/test.  A remote lookup is smart enough to not require java:jboss/exported, but it seems that the local lookup needs java:jboss/ in front of the name.  My argument is that this is inconsistent behaviour.  I should be able to use jms/queue/test regardless if it is a local or remote lookup.  My other point is that the linked document says you can create a queue with the name jms/queue/test when the web administration does not allow that.

                     

                    On a side note, is there any way to get around posting only once per hour?  I have another problem I would like to get help with but I can't when I have to wait an hour between posts.

                    • 7. Re: Re: Re: Question on JNDI names
                      jbertram

                      I'm not sure what's wrong with the web admin console, but I can create a queue like this if I edit the XML directly:

                       

                              <jms-queue name="testQueue"> 
                                  <entry name="jms/queue/test"/> 
                                  <entry name="java:jboss/exported/jms/queue/test"/> 
                              </jms-queue>
                      

                       

                      Or if I use this CLI command:

                       

                      /subsystem=messaging/hornetq-server=default/jms-queue=testQueue/:add(entries=[jms/queue/testQueue,java:jboss/exported/jms/queue/testQueue])
                      

                       

                      And then I can look it up from an MDB using code like this:

                       

                      InitialContext context = new InitialContext();
                      Destination myQueue = (Destination) context.lookup("jms/queue/testQueue");
                      

                       

                      Everything works as expected in my tests.