Skip to content

Instantly share code, notes, and snippets.

@mgagliardo91
Last active June 23, 2021 19:01
Show Gist options
  • Save mgagliardo91/8f62029ba5f0cc95ac7d22b5c77e3027 to your computer and use it in GitHub Desktop.
Save mgagliardo91/8f62029ba5f0cc95ac7d22b5c77e3027 to your computer and use it in GitHub Desktop.
Message Bus Client Retry Mechanism

Message Bus Client Retry Mechanism

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:

Instructions

  1. 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>
  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment