Configure Automatic Client Failover
Sometimes you want a client to failover onto a backup server even if the live server is just cleanly shutdown rather than having crashed or the connection failed. To configure this you can set the property FailoverOnServerShutdown to true either on the HornetQConnectionFactory if you're using JMS or in the hornetq-jms.xml (failover-on-server-shutdown property) file when you define the connection factory, or if using core by setting the property directly on the ClientSessionFactoryImpl instance after creation. The default value for this property is false, this means that by default HornetQ clients will not failover to a backup server if the live server is simply shutdown cleanly. Note By default, cleanly shutting down the server will not trigger failover on the client. Using CTRL-C on a HornetQ server or JBoss AS instance causes the server to cleanly shut down, so will not trigger failover on the client. If you want the client to failover when its server is cleanly shutdown then you must set the property FailoverOnServerShutdown to true By default failover will only occur after at least one connection has been made to the live server. In other words, by default, failover will not occur if the client fails to make an initial connection to the live server - in this case it will simply retry connecting to the live server according to the reconnect-attempts property and fail after this number of attempts. In some cases, you may want the client to automatically try the backup server it fails to make an initial connection to the live server. In this case you can set the property FailoverOnInitialConnection, or failover-on-initial-connection in xml, on the ClientSessionFactoryImpl or HornetQConnectionFactory. The default value for this parameter is false. For examples of automatic failover with transacted and non-transacted JMS sessions, please see Section 11.1.57, “Transaction Failover With Data Replication� and Section 11.1.33, “Non-Transaction Failover With Server Data Replication�.