gpt4 book ai didi

java - Hazelcast 在运行时添加成员

转载 作者:行者123 更新时间:2023-12-02 12:49:51 32 4
gpt4 key购买 nike

我已经创建了一个集群

private static final String IP_CLUSTER = "192.168.0.116:5701";

Config cfg = new Config();
// set IP of cluster
cfg.getNetworkConfig().getJoin().getTcpIpConfig().addMember(IP_CLUSTER).setEnabled(true);
cfg.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);

现在我尝试使用hazelcast-client连接这个集群

HazelcastInstance clientInstance = null;
try {
ClientConfig cfg = new ClientConfig();
ClientNetworkConfig cnc = cfg.getNetworkConfig();
// ip of cluster that i want to connect
cnc.addAddress(IP_CLUSTER);
clientInstance = HazelcastClient.newHazelcastClient(cfg);
}
catch (Exception e) {
return;
}

当我尝试连接客户端时,我在客户端上跟随输出

Jun 19, 2017 8:19:51 PM com.hazelcast.core.LifecycleService INFORMATION: [192.168.0.116]:5701 [dev] [3.7.8] [192.168.0.116]:5701 is STARTED Jun 19, 2017 8:19:56 PM com.hazelcast.nio.tcp.SocketAcceptorThread INFORMATION: [192.168.0.116]:5701 [dev] [3.7.8] Accepting socket connection from /192.168.0.116:60200 Jun 19, 2017 8:19:56 PM com.hazelcast.nio.tcp.TcpIpConnectionManager INFORMATION: [192.168.0.116]:5701 [dev] [3.7.8] Established socket connection between /192.168.0.116:5701 and /192.168.0.116:60200 Jun 19, 2017 8:19:56 PM com.hazelcast.client.impl.protocol.task.AuthenticationMessageTask INFORMATION: [192.168.0.116]:5701 [dev] [3.7.8] Received auth from Connection[id=1, /192.168.0.116:5701->/192.168.0.116:60200, endpoint=null, alive=true, type=JAVA_CLIENT], successfully authenticated, principal : ClientPrincipal{uuid='adaf4c23-a708-489b-9480-dfc7edf960ce', ownerUuid='02d591cc-b572-4e6e-8904-92bd0d8c3610'}, owner connection : true, client version : 3.7.8 Jun 19, 2017 8:20:07 PM com.hazelcast.internal.partition.impl.PartitionStateManager INFORMATION: [192.168.0.116]:5701 [dev] [3.7.8] Initializing cluster partition table arrangement...

表示 -> 新成员已连接到集群。正确吗?

但是当我询问集群上的成员数量时,它始终是1

我哪里有错误?如何向集群添加新成员 (HazelcastInstances)?

最佳答案

正如您自己提到的,您将 Hazelcast 客户端连接到(单节点)集群。客户端只是一个客户端,而不是集群节点。将其想象为连接到数据库的 JDBC 客户端。要扩展集群,您需要启动更多 Hazelcast 成员。

HazelcastInstance hz = Hazelcast.newHazelcastInstance(); // <- creates nodes

HazelcastInstance client = HazelcastClient.newHazelcastClient(); // <- creates a client

关于java - Hazelcast 在运行时添加成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44637548/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com