Hazelcast 5.1 Nearcache Server - Client (no connection found)

Viewed 29

Regarding to the: Hazelcast Nearcache Server - Client Spring Boot

I have the same issue, but with hazelcast 5.1 and java 17:

ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig()
    .setReconnectMode(ClientConnectionStrategyConfig.ReconnectMode.ASYNC)
    .getConnectionRetryConfig().setClusterConnectTimeoutMillis(Integer.MAX_VALUE)
    .setClusterName("cluster_name")
    .addNearCacheConfig(new NearCacheConfig("countries"));
clientInstance = HazelcastClient.newHazelcastClient(clientConfig);

And usage:

var task = new TimerTask() {
    @Override
    public void run() {
        try {
            Map<Integer, Country> countries = clientInstance.getMap("countries");
            if (countries.isEmpty()) {
                System.out.println("Map countries is empty");
            } else {
                for (Integer key : countries.keySet()) {
                    System.out.println("Name: " + countries.get(key).title());
                }
            }
        } catch (Exception ex) {
            System.err.println(ex.getMessage());
        }
    }
}
timer.scheduleAtFixedRate(task, 0, TimeUnit.SECONDS.toMillis(5));

Country class is:

public record Country(Integer id, String title) implements Serializable {
}

The calling with the active server and the client is ok, but when I shutdown the server I got:

No connection found to cluster

Something has been changed in version 5 or my config is wrong?

Thanks

1 Answers

I found that not any method can be used with NearCache: isEmpty() or keySet() will always return no connection because these methods are not proxy-object methods. So I may use getAll() or get() methods here.

Related