Hazelcast: connecting to a remote cluster

We have a cluster of Hazelcast nodes running on one remote system (one physical system with many nodes). We would like to connect to this cluster from an external client - a Java application that uses the code as shown below to connect to Hazelcast:

        ClientConfig clientConfig = new ClientConfig();
        clientConfig.addAddress(config.getHost() + ":" + config.getPort());

        client = HazelcastClient.newHazelcastClient(clientConfig);

      

where host is the IP of the remote, and port is 5701.

This still connects to localhost (127.0.0.1). What am I missing?

Edit:

If the java client is the only application used on the local network, it cannot connect and throws an exception: java.lang.IllegalStateException: Cannot get initial partitions!

From magazines:

14: 58: 26.717 [main] INFO cmbpssHazelcastCacheClient - create a new Hazelcast instance

14: 58: 26.748 [main] INFO com.hazelcast.core.LifecycleService - HazelcastClient [hz.client_0_dev] [3.2.1] - START

14: 58: 27.029 [main] INFO com.hazelcast.core.LifecycleService - HazelcastClient [hz.client_0_dev] [3.2.1] BEGIN

14: 58: 27.061 [hz.client_0_dev.cluster-listener] INFO com.hazelcast.core.LifecycleService - HazelcastClient [hz.client_0_dev] [3.2.1] - CLIENT_CONNECTED

14: 58: 27.061 [hz.client_0_dev.cluster-listener] INFO chclient.spi.ClientClusterService -

Members [5] {Member [127.0.0.1]: 5701 Member [127.0.0.1]: 5702 Member [127.0.0.1]: 5703 Member [127.0.0.1]: 5704 Member [127.0.0.1]: 5705}

14: 58: 47.278 [main] ERROR chcspi.ClientPartitionService - Error while fetching the cluster partition table!

com.hazelcast.spi.exception.RetryableIOException: java.util.concurrent.ExecutionException: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no additional information ... Caused by: java.util.concurrent.ExecutionException : com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no additional information

at java.util.concurrent.FutureTask.report (Unknown source) ~ [Pa: 1.8.0_31]

at java.util.concurrent.FutureTask.get (Unknown source) ~ [na: 1.8.0_31]

at com.hazelcast.client.connection.nio.ClientConnectionManagerImpl.getOrConnect (ClientConnectionManagerImpl.java:282) ~ [BRBASE-service-manager-1.0.0-bank-with-dependencies.jar: on]

... excluded 14 general frames

Throws: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no additional information

at com.hazelcast.util.ExceptionUtil.rethrow (ExceptionUtil.java:45) ~ [BRBASE-service-manager-1.0.0-jar-with-dependencies.jar: na] ...

+3


source to share


3 answers


To connect to a remote cluster, make sure the cluster is using an external IP address and not 127.0.0.1

. In our case, we have a single physical system with several nodes with the enabled mode tcp-ip

. hazelcast.xml

has a configuration:



        <tcp-ip enabled="true">
            <!-- This should be external IP -->
            <interface>172.x.x.x</interface>
        </tcp-ip>

      

+3


source


Can you try:



ClientConfig config = new ClientConfig();
config.getNetworkConfig().addAddress(host + ":" + port);
HazelcastInstance instance = HazelcastClient.newHazelcastClient(config);

      

+1


source


If you want to connect to multiple IP servers running Hazelcast as a cluster add below to your client config and then instantiate the client.

    //configure client properties
    ClientConfig config = new ClientConfig();
    String[] addresses = {"172.20.250.118" + ":" + "5701","172.20.250.49" + ":" + "5701"};
    config.getNetworkConfig().addAddress(addresses);

   //start Hazelcast client
   HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(config);

      

0


source







All Articles