0
votes

I have a very simple Hazelcast client that I'm using to connect to a clustered instace. See that I'm connecting to localhost (127.0.0.1) as well as a remote server (xxx.xx.xx.x).

public HazelcastCacheClient(String mapName, Map<K,V> cacheMap) {

    Config cfg = new Config();
    NetworkConfig networkConfig = cfg.getNetworkConfig();
    networkConfig.setPort(5701);
    networkConfig.setPortCount(1);

    JoinConfig joinConfig = networkConfig.getJoin();
    joinConfig.getMulticastConfig().setEnabled(false);
    joinConfig.getAwsConfig().setEnabled(false);
    joinConfig.getTcpIpConfig()
                    .addMember("127.0.0.1, xxx.xx.xx.x").setEnabled(true);

    HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);

    Map<String, Integer> map = instance.getMap(mapName);
}

I've opened ports 5701-5710 on the CentOS server (xxx.xx.xx.x), but am seeing the following in the logs:

com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [dev] [3.5.5] Resolving domain name 'xxx.xx.xx.x' to address(es): [xxx.xx.xx.x]
com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [dev] [3.5.5] Interfaces is disabled, trying to pick one address from TCP-IP config addresses: [xxx.xx.xx.x/xxx.xx.xx.x, 127.0.0.1]
com.hazelcast.instance.DefaultAddressPicker
INFO: [LOCAL] [dev] [3.5.5] Picked Address[127.0.0.1]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
com.hazelcast.spi.OperationService
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Backpressure is disabled
com.hazelcast.spi.impl.operationexecutor.classic.ClassicOperationExecutor
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Starting with 4 generic operation threads and 8 partition operation threads.
com.hazelcast.system
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Hazelcast 3.5.5 (20160122 - 6805b8e) starting at Address[127.0.0.1]:5701
com.hazelcast.system
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
 com.hazelcast.instance.Node
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Creating TcpIpJoiner
com.hazelcast.core.LifecycleService
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[127.0.0.1]:5701 is STARTING
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to xxx.xx.xx.x/xxx.xx.xx.x:5701, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to xxx.xx.xx.x/xxx.xx.xx.x, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to /127.0.0.1:5703, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to /127.0.0.1:5702, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Connecting to xxx.xx.xx.x/xxx.xx.xx.x:5703, timeout: 0, bind-any: true
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Could not connect to: /127.0.0.1:5702. Reason: SocketException[Connection refused to address /127.0.0.1:5702]
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Could not connect to: /127.0.0.1:5703. Reason: SocketException[Connection refused to address /127.0.0.1:5703]
com.hazelcast.cluster.impl.TcpIpJoiner
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[127.0.0.1]:5702 is added to the blacklist.
com.hazelcast.cluster.impl.TcpIpJoiner
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[127.0.0.1]:5703 is added to the blacklist.
com.hazelcast.nio.tcp.SocketConnector
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Could not connect to: xxx.xx.xx.x/xxx.xx.xx.x:5701. Reason: SocketException[Connection refused to address xxx.xx.xx.x/xxx.xx.xx.x:5701]
com.hazelcast.cluster.impl.TcpIpJoiner
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[xxx.xx.xx.x]:5701 is added to the blacklist.
com.hazelcast.cluster.impl.TcpIpJoiner
INFO: [127.0.0.1]:5701 [dev] [3.5.5] 


Members [1] {
    Member [127.0.0.1]:5701 this
}

Jul 19, 2016 12:32:45 AM com.hazelcast.core.LifecycleService
INFO: [127.0.0.1]:5701 [dev] [3.5.5] Address[127.0.0.1]:5701 is STARTED

As you can see, there's no trouble connecting to localhost (127.0.0.1), but it cannot connect to the remote server xxx.xx.xx.x. I've enabled the port to be accessed through the firewall on the CentOS server for 5701.

Note the following line in particular: INFO: [127.0.0.1]:5701 [dev] [3.5.5] Could not connect to: xxx.xx.xx.x/xxx.xx.xx.x:5701. Reason: SocketException[Connection refused to address xxx.xx.xx.x/xxx.xx.xx.x:5701]

2
Are you trying to connect to an already running cluster or adding another member to a cluster? From the code chunk, I see that you are starting a new cluster itself. Unless you have used the exact same configuration to start the node at xxx.xx.xx.x:5701, it will not be able to join that node to form a cluster and instead it will startup its own cluster.A.K.Desai
If you just intend to start a client then make use of ClientConfig & ClientNetworkConfig and start using HazelcastClient.newHazelcastClient(clientConfig)A.K.Desai

2 Answers

0
votes

Your config looks good, but I assume it's a pseudo-code, since there's no var-arg method addMember. You can invoke the addMember method multiple times or use the setMembers method to add a couple of members.

You didn't post the config of the first node. You need have identical configs - including the cluster name, and password too (if you have defined them).

It can also be a firewall problem still - try doing telnet xxx.xxxx.xxx.xx 5701 to see if the connection can be opened successfully.

0
votes

Matt,

This is how you can create new client

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;

public void HazelcastCacheClient(String mapName, Map cacheMap) {

    ClientConfig cfg = new ClientConfig();
    cfg.getNetworkConfig().addAddress("xxx.xx.xx.x");

    HazelcastInstance instance = HazelcastClient.newHazelcastClient(cfg);

    cacheMap = instance.getMap(mapName);

}

With API that you use, you just start member on localhost. You need to make sure you running Hazelcast member on xxx.xx.xx.x:5701 (default port).

Thank you