0
votes

I have created one cluster

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);

now i try with hazelcast-client to connect this cluster

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;
}

when i try to connect the client, i become on client following output

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...

means -> new member is connected to cluster. Is it correct?

but when i ask for count of members on cluster, it is always 1

Where i have a mistake? How to add new members (HazelcastInstances) to cluster?

2

2 Answers

1
votes

As you mentioned yourself you connected a Hazelcast client to the (one-node) cluster. A client is just a client but not a cluster node. Imagine it as a JDBC client connecting to a database. To scale the cluster you need to start additional Hazelcast members.

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

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

its realy strange to understand, but by many time excution of

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);

there would be:

  • first execution - creates a cluster and add one node to it
  • each next execution - adds a node to existing cluster