JBoss Messaging 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:
retry-interval. This optional parameter determines the period in milliseconds between subsequent reconnection attempts, if the connection to the target server has failed. The default value is 2000 milliseconds.
retry-interval-multiplier. This optional parameter determines determines a multiplier to apply to the time since the last retry to compute the time to the next retry.
This allows you to implement an exponential backoff between retry attempts.
Let's take an example:
If we set retry-interval to 1000 ms and we set retry-interval-multiplier to 2.0, then, if the first reconnect attempt fails, we will wait 1000 ms then 2000 ms then 4000 ms between subsequent reconnection attempts.
The default value is 1.0 meaning each reconnect attempt is spaced at equal intervals.
reconnect-attempts. This optional parameter determines the total number of reconnect attempts the bridge will make before giving up and shutting down. A value of -1 signifies an unlimited number of attempts. The default value is -1.
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 jbm-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 JBossConnectionFactory 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.