A recent version of the message bus client includes updates that will ensure the client will attempt to retry its connection to the server when lost.
Follow the steps below to include the enhancement:
- Bump to the latest version of the message bus client
compile(group = "io.ndustrial", name = "mb-client", version = "1.5.4")
<dependency>
<groupId>io.ndustrial</groupId>
<artifactId>mb-client</artifactId>
<version>1.5.4</version>
</dependency>
- Update the construction of the client
MessageBusClientFactory factory = new MessageBusClientFactory(config);
MessageBusClient client = factory.makeClient(
MessageBusClientOptions.Builder()
.autoReconnect(true)
// .connectionLostTimeoutSeconds(120) // [Optional] defaults to 120
.build()
);
val factory = MessageBusClientFactory(config)
val client = factory.makeClient(
MessageBusClientOptions.Builder()
.autoReconnect(true)
// .connectionLostTimeoutSeconds(120) // [Optional] defaults to 120
.build()
)
The important piece here is autoReconnect(true)
which instructs the client to retry connections when lost. An optional parameter connectionLostTimeoutSeconds
indicates how long until a connection is deemed lost when it has not received proper handshakes. In most cases, the retry will be immediate since most servers will disconnect from clients prior to shutting down, but in the case the network disconnects on the client's side, this value will alter how quickly it is resolved.