We are connecting to an external Hazelcast cluster (version 3.7.2) using the Java Hazelcast client but are having issues reconnecting if the cluster goes down.
We are creating our client with HazelcastClient.newHazelcastClient
. Once we do that, we are keeping a copy of the HazelcastInstance
and using that to interact with the Hazelcast cluster (getMap
, getSet
, etc.). We are also storing the maps, sets, etc. that we get from the HazelcastInstance
in potentially long lived objects. Everything works fine in the happy path. However, if the cluster ever goes down and comes back up, we get HazelcastInstanceNotActiveException
when trying to access these objects that were created prior to the cluster going down.
Is there a way to automatically re-establish the client connection when the cluster comes back online so we can resume using use the objects (maps, sets, etc.) we'd previously retrieved from Hazelcast before the cluster went down? Or do we need to have additional code to catch HazelcastInstanceNotActiveException
and then rebuild the HazelcastInstance
and any objects we have stored in the client application? The latter seems like it will be quite invasive and definitely not desirable to deal with in each instance we store one of these Hazelcast objects.
Most of the things I've read refer to the NetworkConfig
settings for connection timeout, attempt limit, and attempt timeout. We are currently using the default values but they do not seem to do anything when accessing an object we've already retrieved. Any access to a previously existing object immediately fails with HazelcastInstanceNotActiveException
even after the cluster is back up.
This seems like a common problem many people would run into. What is the best practice for dealing with this?
HazelcastInstance
knows if it's running (getLifecycleService().isRunning()
) so it would be nice if it would fail immediately if it's not running but then continually try to reconnect in the background based on some predefined strategy (try every X number of seconds, exponential back-off, etc.). Is anything like this possible? – Immoderation