3 Replies Latest reply on Mar 19, 2014 5:22 PM by Justin Bertram

    JMS Client discovery of Live/Backup server for remote client

    Andrew Morgan Newbie

      I have a live/backup server pair (JBoss EAP 6.2 standalone-full-ha configuration) successfully running HornetQ and failing back and forth as required. I also have a remote client (i.e. not in an application server) that wants to read messages from a Queue on whichever server is active. The client is getting its ConnectionFactory and Queue via JNDI from the active server. My question is, how do I discover which of the two servers is the currently active one?

       

      I see in the User Manual 38.2.1.4.1. how to use the HornetQClient to create a ConnectionFactory that will discover the live server, but I then would want to instantiate a Queue to create a MessageConsumer to read from the queue. How would I determine which of the two servers the Queue in its JNDI?

        • 1. Re: JMS Client discovery of Live/Backup server for remote client
          Justin Bertram Master

          How would I determine which of the two servers the Queue in its JNDI?

          As far as I can tell, this is the essential question you're asking.  Unfortunately I don't understand it.  It seems to be missing one or more important words.

           

          That said, let me give you a little overview on JMS and JNDI that might help...

           

          JMS and JNDI are fundamentally independent.  They are completely different specs and implemented by completely different projects.  The convention outlined by the JMS specification is for clients to leverage JNDI when finding administered objects (e.g. destinations and connection factories), but it's not actually required.  JNDI certainly has no knowledge of HornetQ fail-over/back semantics. 

           

          Therefore, if the client wishes to use JNDI when connecting to a HornetQ live/backup pair it is up to the client to find the active server.  With EAP 6.x I think the simplest way to do this is using multiple URLs in your JNDI look-up.

           

          Does that address your question?  If not, please clarify.

          • 2. Re: JMS Client discovery of Live/Backup server for remote client
            Andrew Morgan Newbie

            True, I missed a word.

             

            How would I determine which of the two servers has the Queue in its JNDI?

             

            Of course, JMS and JNDI are fundamentally independent, I understand that. The point is that that backup HornetQ removes all ConnectionFactories and destinations from the Directory when starts in or returns to backup mode. Using multiple values in the PROVIDER_URL in your InitialContext will fail if the first server in the list is up, but is not the active HornetQ server. You can connect to the directory, but when searching for the JMS objects it will throw an exception because it it not found.

             

            The question therefore is, is there a method using HornetQ to determine which server is live, and has all the required objects in its directory, so the client can connect to the active HornetQ server regardless of which JBoss servers are up?

            • 3. Re: JMS Client discovery of Live/Backup server for remote client
              Justin Bertram Master

              How would I determine which of the two servers has the Queue in its JNDI?

              Try the look-up on one server, if the look-up fails then try the look-up on the other server.

               

              Using multiple values in the PROVIDER_URL in your InitialContext will fail if the first server in the list is up, but is not the active HornetQ server. You can connect to the directory, but when searching for the JMS objects it will throw an exception because it it not found.

              If you keep the URLs ordered properly and use fail-back then this should rarely be a problem.  However, if you're worried about this possibility then see my answer to your previous question.

               

              The question therefore is, is there a method using HornetQ to determine which server is live, and has all the required objects in its directory, so the client can connect to the active HornetQ server regardless of which JBoss servers are up?

              Your question here is two-fold...

               

              Yes, there is a way for a HornetQ client to determine which server is live.  It's outlined in the documentation you cited previously (i.e. section 38.2.1.4.1 here).  It's worth noting that you can avoid JNDI entirely using org.hornetq.api.jms.HornetQJMSClient.  It can create JMS connection factories and destinations.

               

              No, there is no way using HornetQ to determine which server has all the required objects in JNDI.  If you want to know what's in JNDI then you should use the JNDI API, not the HornetQ (or JMS) API.