4 Replies Latest reply on Dec 5, 2013 8:37 AM by snowfi6916

    Problem with Netty in HornetQ

    snowfi6916

      I am getting the following error every time I try to start my server:

       

      WARNING: Unexpected Netty Version was expecting 3.2.5.Final-a96d88c using 3.2.0.BETA1-r2215

      Exception in thread "main" 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 org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:114)

          at blah.blah.HornetQHelloWorld.HornetQHelloWorld.main(HornetQHelloWorld.java:73)

      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:774)

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

          ... 3 more

       

      However, in my POM file, I have this:

       

              <dependency>

                  <groupId>org.hornetq</groupId>

                  <artifactId>hornetq-core</artifactId>

                  <version>2.2.14.Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.hornetq</groupId>

                  <artifactId>hornetq-jms</artifactId>

                  <version>2.2.14.Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.hornetq</groupId>

                  <artifactId>hornetq-logging</artifactId>

                  <version>2.2.14.Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.hornetq</groupId>

                  <artifactId>hornetq-transports</artifactId>

                  <version>2.1.0.r9031</version>

              </dependency>

       

              <dependency>

                  <groupId>org.jboss.netty</groupId>

                  <artifactId>netty</artifactId>

                  <version>3.2.5.Final</version>

              </dependency>

       

              <dependency>

                  <groupId>org.jboss.javaee</groupId>

                  <artifactId>jboss-jms-api</artifactId>

                  <version>1.1.0.GA</version>

              </dependency>

       

      This is my hornetq-configuration xml:

       

      <configuration xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:hornetq">

       

          <connectors>

              <connector name="netty">

                  <factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory</factory-class>

                  <param key="hornetq.remoting.netty.port" value="5446"/>

              </connector>

          </connectors>

          <acceptors>

              <acceptor name="netty">

                  <factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>

                  <param key="hornetq.remoting.netty.port" value="5446"/>

              </acceptor>

          </acceptors>

          <security-enabled>false</security-enabled>

       

      </configuration>

       

      This is my hornetq-jms xml:

       

      <configuration xmlns="urn:hornetq"

                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                  xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">

       

         <connection-factory name="ConnectionFactory">

              <connectors>

                  <connector-ref connector-name="netty"></connector-ref>

              </connectors>

              <entries>

                  <entry name="ConnectionFactory"></entry>

              </entries>

       

          </connection-factory>

       

         <queue name="exampleQueue">

             <entry name="exampleQueue"></entry>

         </queue>

       

      </configuration>


      I have tried everything I can think of to fix this.  Can anyone offer some advice?

        • 1. Re: Problem with Netty in HornetQ
          gaohoward

          Looks like your client didn't get it right. Do you mind uploading your client code here?

          • 2. Re: Problem with Netty in HornetQ
            snowfi6916

            Here is my client.  I have it do a server config in the beginning.

             

            import java.util.HashMap;

            import java.util.Map;

             

            import javax.jms.Connection;

            import javax.jms.JMSException;

            import javax.jms.MessageConsumer;

            import javax.jms.MessageProducer;

            import javax.jms.Queue;

            import javax.jms.Session;

            import javax.jms.TextMessage;

             

            import org.hornetq.api.core.TransportConfiguration;

            import org.hornetq.api.jms.HornetQJMSClient;

            import org.hornetq.api.jms.JMSFactoryType;

            import org.hornetq.core.config.impl.FileConfiguration;

            import org.hornetq.core.server.HornetQServer;

            import org.hornetq.core.server.HornetQServers;

            import org.hornetq.integration.transports.netty.NettyConnectorFactory;

            import org.hornetq.integration.transports.netty.TransportConstants;

            import org.hornetq.jms.client.HornetQConnectionFactory;

            import org.hornetq.jms.server.JMSServerManager;

            import org.hornetq.jms.server.impl.JMSServerManagerImpl;

             

            public class HornetQHelloWorld

            {

                static void startServer()

                {

                    try

                    {

                        FileConfiguration configuration = new FileConfiguration();

                        configuration.setConfigurationUrl("hornetq-configuration.xml");

                        configuration.start();

             

                        HornetQServer server = HornetQServers

                                .newHornetQServer(configuration);

                        JMSServerManager jmsServerManager = new JMSServerManagerImpl(

                                server, "hornetq-jms.xml");

                        jmsServerManager.setContext(null);

                        jmsServerManager.start();

             

                        System.out.println("HornetQ Server Started Successfully!");

                    }

             

                    catch (Exception e)

                    {

                        System.out.println("Error: " + e.getMessage());

                    }

                }

             

                public static void main(String[] args) throws JMSException

                {

                    startServer();

             

                    Connection connection = null;

             

                    try

                    {

                        Queue queue = HornetQJMSClient.createQueue("exampleQueue");

             

                        Map<String, Object> connectionParams = new HashMap<String, Object>();

                        connectionParams.put(TransportConstants.PORT_PROP_NAME, 5446);

             

                        TransportConfiguration transportConfiguration = new TransportConfiguration(

                                NettyConnectorFactory.class.getName(),

                                connectionParams);

             

                        HornetQConnectionFactory cf = HornetQJMSClient

                                .createConnectionFactoryWithoutHA(

                                        JMSFactoryType.CF,

                                        transportConfiguration);

                        connection = cf.createConnection();  //THIS IS WHERE IT IS FAILING

             

                        Session session = connection.createSession(false,

                                Session.AUTO_ACKNOWLEDGE);

             

                        MessageProducer producer = session.createProducer(queue);

             

                        TextMessage message = session

                                .createTextMessage("Hello, this is a test of HornetQ JMS.");

                        System.out.println("Sent message: " + message.getText());

             

                        producer.send(message);

             

                        MessageConsumer consumer = session.createConsumer(queue);

             

                        connection.start();

             

                        TextMessage messageReceived = (TextMessage) consumer

                                .receive(5000);

                        System.out.println("Received message: "

                                + messageReceived.getText());

                    }

             

                    finally

                    {

                        if (connection != null)

                        {

                            connection.close();

                        }

                    }

                }

            }

            • 3. Re: Problem with Netty in HornetQ
              gaohoward

              couple questions:

               

              1. if you are using 2.2.14.final, the following packages seem not right:

              org.hornetq.integration.transports.netty.NettyConnectorFactory;

              org.hornetq.integration.transports.netty.TransportConstants;

              they should be:

              org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;

              org.hornetq.core.remoting.impl.netty.TransportConstants;

              Please check the version

               

              2. Make sure your hornetq-configuration.xml and hornetq-jms.xml are in the classpath so it can be found and loaded.

              • 4. Re: Problem with Netty in HornetQ
                snowfi6916

                I already had the configuration and jms xml's in my classpath, but your first suggestion did the trick!  I deleted the imports for Netty in my java class, and reimported the correct ones (it was showing both the one I was using before and the one you said to use... I use Eclipse 4.3).  I then had to change my configuration xml to:

                 

                <configuration xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:hornetq">

                 

                    <connectors>

                 

                        <connector name="netty">

                 

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

                 

                        </connector>

                 

                    </connectors>

                    <acceptors>

                 

                        <acceptor name="netty">

                 

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

                            <param key="port" value="5446"/>

                 

                        </acceptor>

                 

                    </acceptors>

                    <security-enabled>false</security-enabled>

                 

                </configuration>


                Thanks.