Hazelcast: connecting to remote cluster
Asked Answered
B

3

9

We have a cluster of Hazelcast nodes all running on one remote system (single physical system with many nodes). We would like to connect to this cluster from an external client - a Java application which uses code as 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 remote and port is 5701.

This still connects to the local host (127.0.0.1). What am I missing?

Edit:

If the java client is the only hazelcast app running on the local system, it fails to connect and throws the exception: java.lang.IllegalStateException: Cannot get initial partitions!

From the logs:

14:58:26.717 [main] INFO c.m.b.p.s.s.HazelcastCacheClient - creating new Hazelcast instance

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

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

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

14:58:27.061 [hz.client_0_dev.cluster-listener] INFO c.h.client.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 c.h.c.spi.ClientPartitionService - Error while fetching cluster partition table!

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

at java.util.concurrent.FutureTask.report(Unknown Source) ~[na: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-jar-with-dependencies.jar:na]

... 14 common frames omitted

Caused by: com.hazelcast.core.HazelcastException: java.net.ConnectException: Connection refused: no further information

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

Barrington answered 17/6, 2015 at 5:59 Comment(5)
Please share your Config fileTardif
There is no config file. The config here is an internal class. The host and port are passed as command line arguments to the java client.Barrington
did you try harcoding the address.? does it still connect to the local host.?Tardif
If client's application is started first, it always fails.Tardif
Server is already running. Client is started next.Barrington
B
5

To connect to the remote cluster, make sure the cluster uses the external IP and not 127.0.0.1. In our case we have a single physical system, with multiple nodes, with tcp-ip mode enabled. The hazelcast.xml has the configuration:

<tcp-ip enabled="true">
    <!-- This should be external IP -->
    <interface>172.x.x.x</interface>
</tcp-ip>
Barrington answered 19/6, 2015 at 14:5 Comment(0)
N
1

Can you try:

ClientConfig config = new ClientConfig();
config.getNetworkConfig().addAddress(host + ":" + port);
HazelcastInstance instance = HazelcastClient.newHazelcastClient(config);
Naos answered 17/6, 2015 at 6:43 Comment(5)
this sounds like you have a firewall problemNaos
All are in one network within the company LAN. I can telnet to the target host-port.Barrington
That's weird. Can you test a new version like just today released 3.5? Is server and client using the same version?Naos
What should be settings of the cluster to allow connections from remote? For example, if the remote cluster has tcp-ip enabled with 127.0.0.1 or fixed IPs, will it allow any remote client to connect? Logically, it should not, isn't it? Else it is a security risk.Barrington
The configured IPs are only used in a comparison on requests, if incoming IP is not matching the pre-configured IP(s) the connection is denied. To prevent listening on other IPs you need to set the property "hazelcast.socket.bind.any" to false.Naos
A
1

If you want to connect to multiple ip's running Hazelcast as cluster add below to your client config and then instantiate 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);
Armoured answered 12/7, 2017 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.