How to reconnect a HazelcastClient to HazelcastServer after server restart
Asked Answered
G

1

5

I'm having a problem using the hazelcast in an architecture based on microservice and springboot. I keep one of the applications with being the application that will be the server of hazelcast and the others are clients of this. However if I have to update the application that is the hazelcast server, the clients applications of the cache overturn the connection to the server and when I up the new version of the server these client applications do not reconnect. Is there any off setting the hazelcastclient to be doing pooling on the server to try to reconnect as soon as it comes back? My client is like below:


    @bean
    open fun hazelcastInstance(): HazelcastInstance? {
    return try {
    val clientConfig = ClientConfig()
    HazelcastClient.newHazelcastClient(clientConfig)
    } catch (e: Exception) {
    log.error("Could not connect to hazelcast server, server up without cache")
    null
    }

}

and I receive "com.hazelcast.client.HazelcastClientNotActiveException: Client is shutdown" if my server goes down.

I'm grateful if you could help me

Gelderland answered 2/1, 2018 at 2:59 Comment(0)
A
6

The Connection Attempt Limit and Connection Attempt Period configuration elements help to configure clients' reconnection behaviour. The client will retry as many as ClientNetworkConfig.connectionAttemptLimit times to reconnect to the cluster. Connection Attempt Period is the duration in milliseconds between the connection attempts defined by ClientNetworkConfig.connectionAttemptLimit. Here is an example of how you configure them:

ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setConnectionAttemptLimit(5);
clientConfig.getNetworkConfig().setConnectionAttemptPeriod(5000);

Starting with Hazelcast 3.9, you can use configuration element reconnect-mode to configure how the client will reconnect to the cluster after a disconnection. It has three options (OFF, ON or ASYNC). The option OFF disables the reconnection. ON enables reconnection in a blocking manner where all the waiting invocations will be blocked until a cluster connection is established or failed. The option ASYNC enables reconnection in a non-blocking manner where all the waiting invocations will receive a HazelcastClientOfflineException. Its default value is ON. You can see a configuration example below:

ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig()
               .setReconnectMode(ClientConnectionStrategyConfig.ReconnectMode.ON);
Allegraallegretto answered 2/1, 2018 at 10:50 Comment(1)
Documentation about this decision docs.hazelcast.org/docs/latest/manual/html-single/…Peek

© 2022 - 2024 — McMap. All rights reserved.