3 Replies Latest reply on Jun 29, 2005 2:30 AM by mobetter

    multiple hosts for JNDI providers

    mobetter

      Folks,

      Am in a position where our jms client (when instantiating the message broker) NEEDS to connect to one host (where the JBOSS mq queue is listening) and if that does not respond try and connect to another host where a similar JBOSS mq queue is listening.

      Here is our properties file:
      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

      Currently, we try and connect to JMS on the localhost. This needs to change to accomodate for multiple hosts (two at the moment).

      Do i just add the host to the "java.naming.provider.url" property like the example below:

      "java.naming.provider.url=jnp://host1:1099 jnp://host2:1099"

      Any ideas ...

      Appreciate it much ...

      Mo.

        • 1. Re: multiple hosts for JNDI providers
          genman

          I think you can only have one URL in there at a time. You'll have to write the logic yourself to fail over to the alternative URL if the first one fails.

          • 2. Re: multiple hosts for JNDI providers
            starksm64

            Comma seperated hosts/urls in the Context.PROVIDER_URL are supported.

            public class TestJNDI
            {
             public static void main(String[] args) throws Exception
             {
             Properties env = new Properties();
             env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
             "org.jnp.interfaces.NamingContextFactory");
             env.setProperty(Context.URL_PKG_PREFIXES,
             "org.jboss.naming:org.jnp.interfaces");
             env.setProperty(Context.PROVIDER_URL, "jnp://badhost:1099,jnp://localhost:1099");
             InitialContext ctx = new InitialContext(env);
             Object root = ctx.lookup("");
             System.out.println(root);
             }
            }
            



            • 3. Re: multiple hosts for JNDI providers
              mobetter

              thanks for the info ... will try it out ...