1 Reply Latest reply on Jul 29, 2014 2:05 PM by Justin Bertram

    Problems with reconnecting to HornetQ

    nbrys Newbie

      Hi all,

       

      We're currently developing a software client for hornetQ JMS. Currently, we are expiricing the following problem.

       

      1) We start a standalone HornetQ JMS server (run.bat)

      2) We start our client software and connect to the jms server (we want to consume messages)

      3) We quit the server using stop.bat

      4) We start the server again using run.bat

      5) We can't reconnect to the server.

       

      When our software detects that the server went down, we get the following stack trace:

      Jul 29, 2014 4:39:27 PM org.hornetq.core.protocol.core.impl.RemotingConnectionImpl fail

      WARN: HQ212037: Connection failure has been detected: HQ119015: The connection was disconnected because of server shutdown [code=DISCONNECTED]

      Jul 29, 2014 4:39:27 PM CEST [Thread-81] [SEVERE] An unexpected exception occurred on the connection to the JMS broker

      javax.jms.JMSException: HornetQDisconnectedException[errorType=DISCONNECTED message=HQ119015: The connection was disconnected because of server shutdown]

        at org.hornetq.jms.client.HornetQConnection$JMSFailureListener.connectionFailed(HornetQConnection.java:760)

        at org.hornetq.core.client.impl.ClientSessionFactoryImpl.callSessionFailureListeners(ClientSessionFactoryImpl.java:964)

        at org.hornetq.core.client.impl.ClientSessionFactoryImpl.failoverOrReconnect(ClientSessionFactoryImpl.java:743)

        at org.hornetq.core.client.impl.ClientSessionFactoryImpl.handleConnectionFailure(ClientSessionFactoryImpl.java:583)

        at org.hornetq.core.client.impl.ClientSessionFactoryImpl.access$100(ClientSessionFactoryImpl.java:85)

        at org.hornetq.core.client.impl.ClientSessionFactoryImpl$DelegatingFailureListener.connectionFailed(ClientSessionFactoryImpl.java:1675)

        at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.callFailureListeners(RemotingConnectionImpl.java:570)

        at org.hornetq.core.protocol.core.impl.RemotingConnectionImpl.fail(RemotingConnectionImpl.java:341)

        at org.hornetq.core.client.impl.ClientSessionFactoryImpl$CloseRunnable.run(ClientSessionFactoryImpl.java:1634)

        at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:107)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

        at java.lang.Thread.run(Unknown Source)

      Caused by: HornetQDisconnectedException[errorType=DISCONNECTED message=HQ119015: The connection was disconnected because of server shutdown]

        ... 5 more

       

      After that, our software tries to reconnect every 30 seconds to the broker. This is down by calling to following code:

       

        
      @Override
        protected Connection createConnection(Map<String, String> parameters) throws JMSException
        {
        final String username = parameters.get(kUSERNAME);
        final String password = parameters.get(kPASSWORD);
        final String host = parameters.get("host");
        HornetQConnectionFactory cf = null;
        synchronized (fgConnectionFactories)
        {
        cf = fgConnectionFactories.get(host);
        if(cf == null)
        {
        final Map<String,Object> connectionParameters = new HashMap<String, Object>();
        for(String key : parameters.keySet())
        {
        if(!key.equals(kUSERNAME) && !key.equals(kPASSWORD))
        {
        final String value = parameters.get(key);
        if(value != null && !value.equals(""))
        {
        connectionParameters.put(key, value);
        }
        }
        }
      
        final TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParameters);               
        cf = HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF,transportConfiguration);
        fgConnectionFactories.put(host, cf);
        }
        }
      
        if (username != null && !username.equals(""))
        {
        return cf.createConnection(username, password);
        }
        else
        {
        return cf.createConnection();
        }
      
        }
      
      
      

       

      But this fails on line 39 with the following stacktrace (At that point, the hornetQ server is already restarted!):

       

      Jul 29, 2014 4:39:57 PM org.hornetq.core.client.impl.ClientSessionFactoryImpl getConnection

      WARN: HQ212007: connector.create or connectorFactory.createConnector should never throw an exception, implementation is badly behaved, but we will deal with it anyway.

      org.hornetq.api.core.HornetQInterruptedException: java.lang.InterruptedException

        at org.hornetq.core.remoting.impl.netty.NettyConnection.write(NettyConnection.java:289)

        at org.hornetq.core.remoting.impl.netty.NettyConnection.write(NettyConnection.java:176)

        at org.hornetq.core.remoting.impl.netty.NettyConnector$Listener.connectionCreated(NettyConnector.java:1043)

        at org.hornetq.core.remoting.impl.netty.NettyConnector.createConnection(NettyConnector.java:779)

        at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnection(ClientSessionFactoryImpl.java:1226)

        at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnectionWithRetry(ClientSessionFactoryImpl.java:1072)

        at org.hornetq.core.client.impl.ClientSessionFactoryImpl.connect(ClientSessionFactoryImpl.java:249)

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

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

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

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

        at com.id.jms.impl.hornetq.HornetQMessageQueueServiceImpl.createConnection(HornetQMessageQueueServiceImpl.java:79)

        at com.id.jms.AbstractMessageQueueService.getConnection(AbstractMessageQueueService.java:162)

        ...

      Caused by: java.lang.InterruptedException

        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(Unknown Source)

        at java.util.concurrent.Semaphore.acquire(Unknown Source)

        at org.hornetq.core.remoting.impl.netty.NettyConnection.write(NettyConnection.java:184)

        ... 17 more

       

      Jul 29, 2014 4:39:57 PM CEST [JMS-Transacted-1] [SEVERE] There was a problem while trying to reestablish the connection to the JMS broker, retrying in 30 seconds...

      javax.jms.JMSException: Failed to create session factory

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

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

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

        at com.id.jms.impl.hornetq.HornetQMessageQueueServiceImpl.createConnection(HornetQMessageQueueServiceImpl.java:79)

        ...

      Caused by: HornetQNotConnectedException[errorType=NOT_CONNECTED message=HQ119007: Cannot connect to server(s). Tried with all available servers.]

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

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

        ... 9 more

       

      We are NOT using JNDI and the server is running on "localhost". We are using v2.4.0 for server and client libraries.

       

      Interesting side-node. If we kill the server process, and start hornetQ again, reconnecting works fine.