Chapter 34. Client Reconnection

HornetQ clients can be configured to automatically reconnect to the server in the event that a failure is detected in the connection between the client and the server. If the client successfully reconnects, and the server still has a record of the clients session (i.e. the server was not restarted) then the client will transparently re-attach to the session and it will be able to resume as if nothing had happened.

Client reconnection is also used internally by components such as core bridges to allow them to reconnect to their target servers.

Client reconnection is configured using the following parameters:

If you're using JMS, and you're using the JMS Service on the server to load your JMS connection factory instances directly into JNDI, then you can specify these parameters in the xml configuration in hornetq-jms.xml, for example:

<connection-factory name="ConnectionFactory">
<connector-ref connector-name="netty"/>
<entries>
   <entry name="ConnectionFactory"/>
   <entry name="XAConnectionFactory"/>
</entries>
<retry-interval>1000</retry-interval>
<retry-interval-multiplier>1.5</retry-interval-multiplier>
<reconnect-attempts>1000</reconnect-attempts>
</connection-factory>          
    

If you're using JMS, but instantiating your JMS connection factory directly, you can specify the parameters using the appropriate setter methods on the HornetQConnectionFactory immediately after creating it.

If you're using the core API and instantiating the ClientSessionFactory instance directly you can also specify the parameters using the appropriate setter methods on the ClientSessionFactory immediately after creating it.

If your client does manage to reconnect but the session is no longer available on the server, for instance if the server has been restarted or it has timed out, then the client won't be able to re-attach, and any ExceptionListener or FailureListener instances registered on the connection or session will be called.