8 Replies Latest reply on Feb 18, 2010 5:06 AM by Andy Taylor

    initial connection may fail if noe already failed over

    Andy Taylor Master

      This can happen for statically configured session factories. If you have a session factory configured to connect to node A and fail over to Node B and Node A has gone gone down then any session created will always either  try to reconnect for ever to node A, if recconnectAttempts=-1, or simple fail. This is an issue for managed connections in the app server which are configured like this.

       

      We could add a new flag, say failoverOnInitialConnection, which if set to true we try to connect to the backup server. The code would be something like this in ClientSessionFactory:createSession(...)

       

                        theConnection = getConnectionWithRetry(reconnectAttempts);

       

                        if (theConnection == null)
                        {
                           if(failoverOnInitialConnect && backupConnectorFactory != null)
                           {
                              // We have failed connecting to the main server so:

       

                              connectorFactory = backupConnectorFactory;

       

                              transportParams = backupTransportParams;

       

                              backupConnectorFactory = null;

       

                              backupTransportParams = null;

       

                              theConnection = getConnectionWithRetry(reconnectAttempts);
                           }
                           if (theConnection == null)
                           {
                              if (exitLoop)
                              {
                                 return null;
                              }

       

                              throw new HornetQException(HornetQException.NOT_CONNECTED,
                                                         "Unable to connect to server using configuration " + connectorConfig);
                           }

       

                        }

       

       

      The user can decide howlong to wait before doing this by configuring reconnectAttempts and maxRetryInterval etc.