4 Replies Latest reply on May 8, 2013 12:17 PM by alexeyy

    Can I connect remotely to an embedded JMS Server?

    alexeyy

      Can I connect remotely to an embedded JMS Server?

       

      I want to start an embedded JMS Server:

       

      jmsServer = new EmbeddedJMS();

      ...

      jmsServer.start();

       

      and then connect to it remotely from another JVM (and probably altogether from another machine) via JNDI.

       

      My JNDI initial context porperties are:

       

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

      java.naming.provider.url=jnp://localhost:1099

      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


      When I try to pull this off I get exceptions like

      javax.naming.CommunicationException: Failed to retrieve stub from server localhost/127.0.0.1:1099

      or

      java.net.ConnectException: Connection refused

       

      When I start a standalone server though it works like a charm. What am I doing wrong?

        • 1. Re: Can I connect remotely to an embedded JMS Server?
          ataylor

          There is no jndi server with HornetQ embedded, you would either have to:

           

          a) look up resource using HornetQJMSClient

           

          or

           

          b) instantiate a JNDI server your self and set it via  jmsServer.setRegistry(BindingRegistry registry).

           

          you will also have to make sure you have the appropriate netty acceptor configured.

          • 2. Re: Can I connect remotely to an embedded JMS Server?
            alexeyy

            >b) instantiate a JNDI server your self and set it via  jmsServer.setRegistry(BindingRegistry registry).

             

            Is this it?

            • 3. Re: Can I connect remotely to an embedded JMS Server?
              ataylor

              no, thats just a tutorial on using jndi.

               

              You will need to instantiate a naming server yourself, how you do this depends on the naming server you use. For the standalone hornetq version we use the jboss naming server and instantiate it in the StandaloneNamingServer class, take a look at this to see how it works. you then set a JndiBindingregistry with the correct context for your naming server via the setRegistry method

              1 of 1 people found this helpful
              • 4. Re: Can I connect remotely to an embedded JMS Server?
                alexeyy

                Ok. Thank you, Andy!

                 

                Edit: I've finally got around to tackle my little JMS problem. For the purposes of my application I needed to run an embedded JMS server and a consumer on one JVM, and a producer on another JVM. Ended up using HornetQJMSClient, it worked like charm. I set up mock InitialContext ctx, and populated it (via ctx#bind) with contents of hornetq-jms.xml, instantiating objects via HornetQJMSClient. Andy, you've saved me a bucha' time, thank you so much!