Artyom
Artyom

Reputation: 25

Cannot override properties in Hazelcast.yaml for Spring Boot Application

I have Spring Boot application with Hazelcast (use 4.2 and also try to use 4.0.3 of hazelcast-all dependency). Hazelcast is configured for embedded topology. I use TCP-IP network join way. Properties for Hazelcast are set using file Hazelcast.yaml and Spring Boot property: spring.hazelcast.config (Spring by default use this name for Hazelcast config, it is redundant).

In property member-list I indicate IP addresses of two machines in one subnet (e.g. 192.0.0.1 and 192.0.0.2).

I build application in Docker using image based on Alpine on OpenJdk. Image includes start java -jar command as ENTRYPOINT.

PROBLEM PREMISE:

I run two docker containers on two machines described earlier. I forward only port 5701 (using -p) on both containers. And containers don't see each other. Spring Boot logs show that the container network is being used.

PS:

  1. All work if run docker with --net host.
  2. Also all work if I package Spring Boot application with property public-address in Hazelcast.yaml for two containers - once package with value 192.0.0.1, the other with value 192.0.0.2. Spring Boot Hazelcast instances see each other using network of machine (192.0.0.1 and 192.0.0.2).

PROBLEM:

I try to override property public-address in Hazelcast.yaml using:

Nothing works. Does anyone know why it is not possible to override property public-address in the Hazelcast.yaml at startup?

Or maybe anyone knows how I can run two Spring Boot applications with embedded Hazelcast in separate Docker containers on separate machines.

Upvotes: 0

Views: 2264

Answers (1)

Rafał Leszko
Rafał Leszko

Reputation: 5541

The way you set up Hazelcast public address is correct, at least starting from Hazelcast 4.1 where the Config Override feature was added.

To check the working version, you can have a look at Hazelcast Guide: Embedded Hazelcast on Kubernetes. Instead of Hazelcast Kubernetes configuration, you can use TCP-IP. The following Hazelcast configuration worked for me (my host IP is 172.22.41.210).

hazelcast:
  cluster-name: hazelcast-cluster
  network:
    join:
      tcp-ip:
        enabled: true
        member-list:
          - 172.22.41.210:5701
          - 172.22.41.210:5702

Then, building and starting two applications should form a cluster.

$ mvn package && docker build -t hazelcast-embedded .
$ docker run --rm -e HZ_NETWORK_PUBLICADDRESS=172.22.41.210 -p 5701:5701 hazelcast-embedded
$ docker run --rm -e HZ_NETWORK_PUBLICADDRESS=172.22.41.210:5702 -p 5702:5701 hazelcast-embedded

You should see that the cluster was formed in the application logs.

Members {size:2, ver:2} [
        Member [172.22.41.210]:5701 - 21af9e1a-7e98-4305-905c-451ee23486c3 this        
        Member [172.22.41.210]:5702 - 0507d970-1f31-4df3-9ea5-8c3981eb7c98     
]

Upvotes: 2

Related Questions