4 Replies Latest reply on Aug 28, 2014 12:15 AM by Damith K

    Connecting to Remote Jboss hornetq Error : javax.jms.JMSException: Failed to create session factory

    Damith K Newbie

      Hi,

       

      I have a Remote server Jboss with hornetq ( Version 6.1.0.Final "Neo".  I know this is an old version yet I need to stick to it).

      Here is the settings in hornetq-configuration.xml in remote server.

      <acceptors> 

            <acceptor name="netty">

               <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>

               <param key="host"  value="${jboss.esb.bind.address:10.77.4.134}"/>

               <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>

            </acceptor>    

            <acceptor name="netty-throughput">

               <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>

               <param key="host"  value="${jboss.bind.address:localhost}"/>

               <param key="port"  value="${hornetq.remoting.netty.batch.port:5455}"/>

               <param key="batch-delay" value="50"/>

               <param key="direct-deliver" value="false"/>

            </acceptor>

            <acceptor name="in-vm">

              <factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>

              <param key="server-id" value="0"/>

            </acceptor>

         </acceptors>

       

      And this is how my client, which is another Jboss with same version in another PC.

      Client  hornetq-configuration.xml like below. I only changed the<connector name="netty"> server ip (10.77.4.134).

       

      <connectors>

            <connector name="netty">

               <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>

               <param key="host"  value="${10.77.4.134}"/>    <!-- this settings I got from url : Hornetq2.2.2 client failed to create session factory to connect on server -->

               <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>

            </connector>

            ....

      </connectors>

       

      And below is how client connect to the remote server.

       

        Properties prop = new Properties();

        prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

        prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

        prop.put(Context.PROVIDER_URL, "jnp://10.77.4.134:1099");

        prop.put("jboss.naming.client.ejb.context", true);

        ictx = new InitialContext(prop);

        conFactory = (ConnectionFactory)ictx.lookup("/ConnectionFactory");

       

        qcon  = (QueueConnection)conFactory.createConnection();

        qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE)

       

      --------------------------------------------------------------------------------------------

      I get the below error when it execute the line      qcon  = (QueueConnection)conFactory.createConnection();

       

      Error : javax.jms.JMSException: Failed to create session factory

        at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:673) [:6.1.0.Final]

        at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:112) [:6.1.0.Final]

        at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:107) [:6.1.0.Final]

       

      Can anyone help me pls? any additional settings I need to do in Remote server or in Client side? This is perfectly working in client and server is in same Jboss with default netty settings.

        • 1. Re: Connecting to Remote Jboss hornetq Error : javax.jms.JMSException: Failed to create session factory
          Justin Bertram Master

          The configuration of everything you've pasted looks fine to me.  Can you attach or paste your hornetq-jms.xml so I can see how your JMS connection factories are configured?  Also, please attach the log file that includes the server start-up process so we can ensure the server is initializing as expected.

          • 2. Re: Connecting to Remote Jboss hornetq Error : javax.jms.JMSException: Failed to create session factory
            Damith K Newbie

            Hi Justin,

             

            Yes, it's working fine now. The problem was I have add some additional jars to my application (<artifactId>hornetq-jms-client</artifactId>) which is not useful and gave the above error. I will post whole setup for the benefit of others later here.

             

            Now I can send messages to the remote queue. But now I want to know how can I read the messages from the remote queue. I have ejb-jar.xml with below settings. And I don't know what are the settings to do this to read a remote destination queue. Can you please help me on this?

             

            <enterprise-beans>

              <message-driven>

              <ejb-name>User4</ejb-name>

              <ejb-class>com.client.receiver.MessageReceiverBean</ejb-class>

              <messaging-type>javax.jms.MessageListener</messaging-type>

              <transaction-type>Container</transaction-type>

              <activation-config>

              <activation-config-property>

              <activation-config-property-name>destinationType</activation-config-property-name>

              <activation-config-property-value>javax.jms.Queue</activation-config-property-value>

              </activation-config-property>

              <activation-config-property>

              <activation-config-property-name>destination</activation-config-property-name>

              <activation-config-property-value>queue/User4</activation-config-property-value>

              </activation-config-property>

              </activation-config>

              </message-driven>

            </enterprise-beans>

            • 3. Re: Connecting to Remote Jboss hornetq Error : javax.jms.JMSException: Failed to create session factory
              Justin Bertram Master

              Take a look at the Java EE examples that ship with HornetQ (e.g. jca-remote).

              • 4. Re: Connecting to Remote Jboss hornetq Error : javax.jms.JMSException: Failed to create session factory
                Damith K Newbie

                Hi ,

                 

                I was able to connect to remote server and get the response from the remote queue. Both my client and server running in two separate computers,  JBossAS [6.1.0.Final "Neo"].

                My client is a simple web app ( a war file)

                 

                Client side queue sender class.

                 

                private static void prepareContext() {

                        logger.debug("Loading Context");

                        try {

                        Properties prop = new Properties();

                        prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                        prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                        prop.put(Context.PROVIDER_URL, "jnp://10.1.4.48:1099");

                        ictx = new InitialContext(prop);

                        conFactory = (ConnectionFactory)ictx.lookup("/ConnectionFactory");

                        qcon  = (QueueConnection)conFactory.createConnection();

                        qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

                        }

                        catch (NamingException er) {

                          logger.fatal("Error ", er);

                        }

                        catch (JMSException er) {

                            logger.fatal("Error ", er);

                        }

                    }

                 

                public static boolean sendToQueue(String xml, String sendQ) {

                        logger.warn("Sending to queue: " + xml);

                        try {

                            prepareContext();

                            Queue queue =  getQueue(sendQ);

                            if (null == queue) {

                                throw new JMSException("Queue not defined at the end point");

                            }

                            qcon.start();

                            QueueSender qsender = qsession.createSender(queue);

                            TextMessage tmsg = qsession.createTextMessage();

                            tmsg.setText(xml);

                            qsender.send(tmsg);

                            return true;

                        }

                        catch (JMSException er) {

                            logger.fatal("Error ", er);

                        }

                        finally {

                           try { qsession.close(); } catch (Exception er) {/**/}

                            try { qcon.close(); } catch (Exception er) {/**/}

                        }

                        return false;

                    }

                 

                 

                 

                Now let's see how client side  message receiver.

                I used MDB to listen remote server queue.

                 

                public class MessageReceiverBean implements MessageListener {

                 

                public void onMessage(Message message) {

                          try {

                            if (message instanceof TextMessage) {

                                TextMessage textMsg = (TextMessage) message;

                                logger.info("Inside onMessage of client app MessageReceiverBean : " + textMsg.getText());

                     }

                  }

                          catch (Exception er) {

                            logger.error("Error while retrieving message from Service provider", er);

                        }

                }

                }

                 

                MDB configuration is in ejb-jar.xml in the META-INF folder of my war file.

                 

                <message-driven>

                  <ejb-name>User1</ejb-name>

                  <ejb-class>com.my.MessageReceiverBean</ejb-class>

                  <messaging-type>javax.jms.MessageListener</messaging-type>

                  <transaction-type>Container</transaction-type>

                  <activation-config>

                  <activation-config-property>

                  <activation-config-property-name>destinationType</activation-config-property-name>

                  <activation-config-property-value>javax.jms.Queue</activation-config-property-value>

                  </activation-config-property>

                  <activation-config-property>

                  <activation-config-property-name>destination</activation-config-property-name>

                  <activation-config-property-value>queue/User4</activation-config-property-value>

                  </activation-config-property>

                  <activation-config-property>

                  <activation-config-property-name>ConnectorClassName</activation-config-property-name>

                  <activation-config-property-value>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</activation-config-property-value>

                  </activation-config-property>

                  <activation-config-property>

                  <activation-config-property-name>ConnectionParameters</activation-config-property-name>

                  <activation-config-property-value>host=10.1.4.48;port=5445</activation-config-property-value>

                  </activation-config-property>

                  </activation-config>

                </message-driven>

                 

                Above bold section is additionally added to connect to the remote server. Java coding is over now. Above is complete native Java class for remote client queue sender.

                 

                But you might interest to do it through EJB CDI injection.

                For that you need to modify below settings in client JBoss side.

                 

                There are two settings I changed in the client  Jboss node.

                 

                1.  hornetq-configuration.xml in client Jboss node.

                <connector name="netty">

                         <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>

                         <param key="host"  value="${MY-IP:10.1.4.48}"/>   <!-- bold part only I changed. 'MY-IP' is just a word. And IP is the remote server ip. Remaining things are original values in Jboss-->

                         <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>

                      </connector>

                 

                2. ra.xml file in  jms-ra.rar (deploy folder) in  client Jboss node.

                Comment the below settings like this.

                <!--<config-property>

                         <description>The transport configuration. These values must be in the form of key=val;key=val;,

                            if multiple connectors are used then each set must be separated by a comma i.e. host=host1;port=5445,host=host2;port=5446.

                            Each set of params maps to the connector classname specified.

                         </description>

                         <config-property-name>ConnectionParameters</config-property-name>

                         <config-property-type>java.lang.String</config-property-type>

                         <config-property-value>server-id=0</config-property-value>

                      </config-property>-->

                 

                Ok. JBoss settings are over. Now let's see the Entity Bean. We need to inject the above connection through Annotation.

                @Resource(mappedName = "/ConnectionFactory")

                private QueueConnectionFactory qConnectionFactory;

                 

                If you check your hornetq-jms.xml you can see under <connection-factory name="NettyConnectionFactory"> above mappedName is defined ( <entry name="/ConnectionFactory"/> ). This is the JNDI name you should look in your EJB, to find the connectionFactory in the remote HornetQ server. That's it if you need to use EJB CDI injection rather than native JNDI lookup.

                 

                Restart the client JBoss, then you should be able to send the messages from client to Server. (No special settings in starting the JBoss)

                 

                You can verify where is it connecting, if you go to jmx-console of the client and go to org.hornetq, then click on module=JMS,name="NettyConnectionFactory",type=ConnectionFactory. In StaticConnectors you see where this NettyConnector is connecting.

                 

                Now server side Jboss HornetQ settings.

                 

                Edit the hornetq-configuration.xml in Server JBoss and change the <acceptors>  section.

                 

                <acceptor name="netty">

                         <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>

                         <param key="host"  value="${jboss.esb.bind.address:10.1.4.48}"/> <!-- Here I add the server IP and esb. May be you can remove the esb and use "jboss.bind.address:10.1.4.48" -->

                         <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>

                      </acceptor>

                 

                So this is server Jboss settings. And I start the server with run.bat -b 10.1.4.48  option.

                 

                Hope this helps.