Hazelcast 5.1近距离服务器 - 客户端(找不到连接)
关于: 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现,没有任何方法可以与近孔一起使用:
isempty()
或keyset()
始终不会返回连接,因为这些方法不是proxy-object方法。因此,我可以在此处使用getall()
get()方法。I found that not any method can be used with NearCache:
isEmpty()
orkeySet()
will always return no connection because these methods are not proxy-object methods. So I may usegetAll()
orget()
methods here.