7

I'm trying to Directly instantiating JMS Resources without using JNDI to a REMOTE HORNETQ.

I am running my test code in Eclipse IDE. Setup my classpath to use the HornetQ 2.2.5 libraries.

The target HornetQ is version 2.1.2.Final, I figured they should be backwards compatible, maybe im wrong?

Okay, so I have read the online documentation and followed the examples on connecting to a remote JMS server without using JNDI. I keep on getting the following exception. Im not sure what Im missing but I believe I have everything setup correctly. Could someone please point out what Im missing here? Thanks in advance.

JMSException: Failed to create session factory

The connector on hornetq-configuration.xml is:

  <connector name="netty">
     <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
          <param key="host"  value="${10.100.111.222}"/>
          <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
  </connector>

The acceptor is:

  <acceptor name="netty">
     <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
      <param key="host"  value="${10.100.111.222}"/>
     <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
  </acceptor>

My Test code is: Connection connection = null;

   try
   {
    Queue queue = HornetQJMSClient.createQueue("TESTQ");

    Map<String, Object> connectionParams = new HashMap<String, Object>();
    connectionParams.put(TransportConstants.PORT_PROP_NAME, 5445);
    connectionParams.put(TransportConstants.HOST_PROP_NAME, "10.100.111.222");        

    TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(),
                                                                               connectionParams);
    ConnectionFactory factory = (ConnectionFactory) HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);
    System.out.println("debug: " + factory.getClass());

    connection = factory.createConnection();

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

    MessageProducer producer = session.createProducer(queue);

    TextMessage message = session.createTextMessage("This is a test message");
    System.out.println("Sent message: " + message.getText());

    producer.send(message);

   }
      finally
      {
         if (connection != null)
         {
            try {
                connection.close();
            } catch (JMSException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
         }
      }

I get the following Exception

SEVERE: Failed to create netty connection
java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at org.jboss.netty.channel.socket.oio.OioClientSocketPipelineSink.connect(OioClientSocketPipelineSink.java:114)
    at org.jboss.netty.channel.socket.oio.OioClientSocketPipelineSink.eventSunk(OioClientSocketPipelineSink.java:74)
    at org.jboss.netty.channel.Channels.connect(Channels.java:541)
    at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:218)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
    at org.hornetq.core.remoting.impl.netty.NettyConnector.createConnection(NettyConnector.java:450)
    at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnection(ClientSessionFactoryImpl.java:1016)
    at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnectionWithRetry(ClientSessionFactoryImpl.java:897)
    at org.hornetq.core.client.impl.ClientSessionFactoryImpl.connect(ClientSessionFactoryImpl.java:212)
    at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:602)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:611)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:121)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:116)
    at com.ws.proto.ManualJMS.main(ManualJMS.java:39)
Oct 19, 2011 1:18:50 PM org.hornetq.core.logging.impl.JULLogDelegate warn
WARNING: Tried 1 times to connect. Now giving up on reconnecting it.
Exception in thread "main" javax.jms.JMSException: Failed to create session factory
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:615)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:121)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:116)
    at com.ws.proto.ManualJMS.main(ManualJMS.java:39)
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:619)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:611)
    ... 3 more
Byron
  • 3,833
  • 9
  • 34
  • 39

1 Answers1

8

Regarding compatibility: We didn't have client compatibility until 2.2.5+. If you try client on 2.2.2 and server at 2.2.5, you will probably get a version mismatch exception.

We are aiming to always be compatible from 2.2.5+

And you have a typo in your config:

  <connector name="netty">
     <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
          <param key="host"  value="10.100.111.222"/>
          <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
  </connector>

We use a syntax for properties and default values. You could for instance define a variable MY_IP and use it as:

"${MY_IP:10.100.111.222}"

If MY_IP is null, you would get 10.100.111.222

But "${10.100.111.222}" doesn't mean anything.

Clebert Suconic
  • 5,353
  • 2
  • 22
  • 35
  • Please don't forget to accept the answer if that solves your issue! :) I"m trying to collect points on SOF (for fun only probably :) ) – Clebert Suconic Oct 19 '11 at 21:12
  • I've corrected my syntax error following your example and see in the boot.log that it binds correctly. But I am still getting the same error message. Since the client is using 2.2.5 the compatibility should not be an issue, right? – Byron Oct 19 '11 at 22:55
  • If server and client are on the same version, it shouldn't be an issue. if you are not being able to connect, you probably have a network issue. I see that the instantiate connection example works fine if I add the IP. – Clebert Suconic Oct 20 '11 at 03:31
  • I'm working with networking at my company to see if there is a firewall issue. Thanks @Clebert – Byron Oct 20 '11 at 23:19
  • You should either accept the answer or tell me if you are still having issues... Unless you are still having issues. You could do that on any other computer to make sure about firewal issues. – Clebert Suconic Oct 21 '11 at 14:06
  • @Clebert Thank you sir, I used like ${MY_IP:10.100.111.222} and it perfectly connecting to the remote Jboss server hornetq. This I added for reference of others. I also have add my own question and answer here. http://stackoverflow.com/questions/25397138/jboss-client-send-message-to-remote-hornetq-in-jboss – user2771655 Aug 28 '14 at 03:14