3
votes

I have a Vert.x server application on the Hazelcast cluster and clients connecting to the cluster. The application is deployed in Docker container. The container has a network adapter with the bridged address 172.17.0.2, and linux host, in which the container is running, has network adapter with the address 192.168.107.105. In the container properties, the forwarding of ports 1199 and 5702 to an external network adapter is configured and working well.

from docker inspect :

"ExposedPorts": {
                "1199/tcp": {},
                "5702/tcp": {}
            },

Port 1199 used by other service. Port 5702 is specified in Hazelcast.setOptions():

NetworkConfig().setPort(5702)

Client workstations reside in 192.168.108.* subnet. Telnet 192.168.107.105 5702 works excellent. Telnet 172.17.0.2 5702 doesn’t work, of course.

Client application successfully connects to Hazelcast cluster (client logs):

INFO: hz.client_0 [dev] [3.8.2] Authenticated with server [192.168.107.105]:5702, server version:3.8.2 Local address: /192.168.108.127:49424
Mar 23, 2018 11:54:02 PM com.hazelcast.client.spi.impl.ClientMembershipListener
INFO: hz.client_0 [dev] [3.8.2]

Members [1] {
        Member [192.168.107.105]:5702 - 86005036-d0f2-439e-b056-d30f53d3aabd
}

Mar 23, 2018 11:54:02 PM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [dev] [3.8.2] HazelcastClient 3.8.2 (20170518 - a60f944) is CLIENT_CONNECTED
Connected to Hazelcast cluster: /192.168.107.105

Then it successfully connects to Vert.x cluster, I suppose. But message send fails - client application trying to connect to local address of the Vert.x instance!

(CASE 1): Client logs:

Connected to Vert.x cluster
Mar 23, 2018 11:54:05 PM io.vertx.core.eventbus.impl.clustered.ConnectionHolder
WARNING: Connecting to server localhost:34030 failed
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:34030

(CASE 2): If I change in server app VertxOptions.clusterHost to 192.168.107.105:

VertxOptions().setClusterManager(mgr).setClusterHost(“192.168.107.105”) 

then error changes to:

Server logs:

SEVERE: Failed to start event bus
java.net.BindException: Cannot assign requested address

(CASE 3): If I change VertxOptions.clusterHost to 172.17.0.2:

VertxOptions().setClusterManager(mgr).setClusterHost(“172.17.0.2”) 

then server starts OK, but now client fails to send messages:

WARNING: Connecting to server 172.17.0.2:34030 failed
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: someserver/172.17.0.2:34030

When I deploy the server application not in the docker container on a network adapter that is directly accessible from the client network, then everything works fine. Also message publish() initiated from the server side successfully delivers messages to all subscribed clients - both inside the container and outside it.

How should I configure the client and server applications, so that they work correctly? Is it possible to use only bridged network in container for that case?

ADDED: I think, I should expose separate port for vert.x clustering in container properties. But at this point, I suppose, the problem is that (CASE 1 and 3) the client application is trying to connect to the internal address of the container. Or in the other side (CASE 2) - Vert.x cluster cannot start on external address, that can access client application.

1

1 Answers

4
votes

I'm sorry. I found the answer: How do I configure Vert.x event bus to work across cluster of Docker containers?

Just set VertxOptions().clusterPublicHost("192.168.107.105") - in same manner as in Hazelcast...

    VertxOptions()
            .setClusterHost("172.17.0.2")
            .setClusterPort(18001)
            .setClusterManager(mgr)
            .setClusterPublicHost("192.168.107.105")

Now error changed, but it is because I didn't forwarded cluster port to host network interface. Problem solved :)