Hazelcast 5.1近距离服务器 - 客户端(找不到连接)

发布于 2025-01-26 11:57:48 字数 1672 浏览 3 评论 0原文

关于: Hazelcast nearCache nearCache Server-

客户,但是使用Hazelcast 5.1和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);

使用:

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类是:

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

使用Active Server和客户端的呼叫可以,但是当我关闭服务器时,我得到的服务器:

找不到群集的连接

在版本5中更改了某些东西,或者我的配置是错误的?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我太投入 2025-02-02 11:57:48

我发现,没有任何方法可以与近孔一起使用:isempty()keyset()始终不会返回连接,因为这些方法不是proxy-object方法。因此,我可以在此处使用getall() get()方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文