9 Replies Latest reply on Oct 19, 2012 11:11 AM by lucapaone

    "Failed to create session factory"  from client connecting to jboss-as7 hornetq

    lucapaone

      Hi , I am trying to connect from a remote host to a Hornetq embedded in jboss as7. whith this code:

       

       

        env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());

       

      env.put(Context.PROVIDER_URL, "remote://192.168.81.17:4447");

       

        env.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");

       

      initialContext = new InitialContext(env);

                      ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory");

                      connection = cf.createConnection("guest", "guest");

       

                    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

       

      But I receive this error

       

      javax.jms.JMSException: Failed to create session factory

                at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:605)

                at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:119)

                at com.sistemaits.vao.XMLReceiver.runExample(XMLReceiver.java:163)

                at com.sistemaits.vao.XMLReceiver.main(XMLReceiver.java:63)

      Caused by: HornetQException[errorCode=2 message=Cannot connect to server(s). Tried with all available servers.]

                at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:769)

                at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:601)

                ... 3 more

      ERROR RemoteNamingStoreV1 - Channel end notification received, closing channel Channel ID 96523c98 (outbound) of Remoting connection 26789869 to /192.168.242.128:4447

       

       

      while on the server I can see:

      09:21:39,566 INFO  [org.jboss.as.naming] (Remoting "win-gv9pboi9ea1" task-1) JBA

      S011806: Channel end notification received, closing channel Channel ID 16523c98

      (inbound) of Remoting connection 52a9fd96 to /192.168.242.1:42587

       

      From debug I can see that the exception is launched in the line:

        connection = cf.createConnection("guest", "guest");

       

       

      Can someone help us to find where we have an error?

        • 1. Re: "Failed to create session factory"  from client connecting to jboss-as7 hornetq
          ataylor

          first thing ive noticed is you are looking up the wrong jndi name for the connection factory, it should be 'java:jboss/exported/jms/RemoteConnectionFactory'. I would start by looking at one of the javaee examples in HornetQ master or one of the AS7 quick starts

          • 2. Re: "Failed to create session factory"  from client connecting to jboss-as7 hornetq
            lucapaone

            I tried but now the app stops even the line before in

             

              ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("java:jboss/exported/jms/RemoteConnectionFactory");

             

            What is the reason?

             

             


            • 3. Re: "Failed to create session factory"  from client connecting to jboss-as7 hornetq
              ataylor

              Have you tried any of the examples or quickstarts?

              • 4. Re: "Failed to create session factory"  from client connecting to jboss-as7 hornetq
                jbertram

                Actually, you should be using "jms/RemoteConnectionFactory" just like the JMS quick-start.  Based on the log on the server it looks to me like the JNDI lookup is succeeding.  However, the fact that you're getting "Cannot connect to server(s). Tried with all available servers." tells me that perhaps your HornetQ connector is not configured correctly.  Are you binding AS7 to 0.0.0.0?

                • 5. Re: "Failed to create session factory"  from client connecting to jboss-as7 hornetq
                  lucapaone

                  No way , i tried all the suggested names.

                   

                  I solved using instead of the JMS lookup

                   


                  ConnectionFactory cf = (ConnectionFactory)

                                   initialContext.lookup(connectionfactory);

                   

                   

                  the netty classes:

                   

                                  Properties env = new Properties();

                                  // env.put(Context.INITIAL_CONTEXT_FACTORY,

                                  env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());

                                  env.put(Context.PROVIDER_URL, jndi_provider_url);

                                  env.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");

                                  initialContext = new InitialContext(env);

                                  HashMap map = new HashMap();

                                  map.put("host", netty_url);

                                  map.put("port", 5445);

                                  TransportConfiguration transportConfiguration = new TransportConfiguration("org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", map);

                                  ConnectionFactory connectionFactory = (ConnectionFactory) HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.TOPIC_CF, transportConfiguration);

                                  connection = connectionFactory.createConnection();

                   

                  AND ALL worked

                  • 6. Re: "Failed to create session factory"  from client connecting to jboss-as7 hornetq
                    jbertram

                    This makes me think even more that the HornetQ connector(s) in your AS7 instance are not configured correctly.  You see, when you do a JNDI look-up for a connection factory you download a connector which is basically just a simple stub which hold a bit of information (e.g. the host and port of the server) which the client then uses to connect to the server.  If the connector isn't configured correctly on the server then even if the JNDI lookup succeeds when the client downloads the connector it will have problems connecting to the server (e.g. it will receive "Cannot connect to server(s). Tried with all available servers.").

                     

                    If you're ok with just instantiating the connection factory via HornetQJMSClient.createConnectionFactoryWithoutHA() then you can remove all the code dealing with the InitialContext.

                    • 7. Re: "Failed to create session factory"  from client connecting to jboss-as7 hornetq
                      lucapaone

                      I tried to remove the initialcontext stuff but the code fails! It seems it is needed for some reasons....

                       

                      In the first message I attached the jboss configuration (standalone-full.xml) we are using on the remote host. Could you try to see if therte is something wrong in the Hornetq configuration?

                      • 8. Re: "Failed to create session factory"  from client connecting to jboss-as7 hornetq
                        jbertram

                        I tried to remove the initialcontext stuff but the code fails! It seems it is needed for some reasons....

                        My guess is that you're still using JNDI to lookup the JMS destination.

                         

                         

                        In the first message I attached the jboss configuration (standalone-full.xml) we are using on the remote host. Could you try to see if therte is something wrong in the Hornetq configuration?

                        I looked at the standalone-full.xml you attached and I see a potential problem:

                         

                                <interface name="public">

                                    <inet-address value="${jboss.bind.address:0.0.0.0}"/>

                                </interface>

                         

                        If you are not explicitly setting the "jboss.bind.address" when the server boots (either via -Djboss.bind.address or -b) then it will bind to 0.0.0.0.  I asked about this earlier and you said, "No way , i tried all the suggested names," although I'm not sure what you meant by that.  If AS7 is binding to 0.0.0.0 then you will have problems as outlined in HORNETQ-952.

                        • 9. Re: "Failed to create session factory"  from client connecting to jboss-as7 hornetq
                          lucapaone

                          I think this is the problem!

                           

                          Thank you so much!

                           

                          (I was saying I tried all the jms/ConnectionFactort .. REmoteConnectionFActory ... etc)