HornetQ JMSException:无法创建会话工厂

时间:2011-10-19 20:48:03

标签: jms hornetq

我正在尝试直接实例化JMS资源而不使用JNDI到REMOTE HORNETQ。

我在Eclipse IDE中运行我的测试代码。设置我的类路径以使用HornetQ 2.2.5库。

目标HornetQ是版本2.1.2.Final,我认为他们应该向后兼容,也许我错了?

好的,我已经阅读了在线文档并按照连接到远程JMS服务器的示例而不使用JNDI。我继续得到以下异常。我不知道我错过了什么,但我相信我已经正确设置了一切。有人可以指出我在这里失踪了吗?提前谢谢。

JMSException:无法创建会话工厂

hornetq-configuration.xml上的连接器是:

  <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>

接受者是:

  <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>

我的测试代码是:       连接连接= 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();
            }
         }
      }

我得到以下例外

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

1 个答案:

答案 0 :(得分:8)

关于兼容性:我们在2.2.5+之前没有客户端兼容性。如果您在2.2.2上尝试客户端,在2.2.5上尝试服务器,则可能会出现版本不匹配异常。

我们的目标是始终与2.2.5 +

兼容

你的配置中有拼写错误:

  <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>

我们使用属性和默认值的语法。例如,您可以定义变量MY_IP并将其用作:

“$ {MY_IP:10.100.111.222}”

如果MY_IP为空,您将获得10.100.111.222

但“$ {10.100.111.222}”并不意味着什么。