Eureka is out of sync

I am prototyping a Spring Cloud + Netflix OSS application suite and have run into problems with Eureka. In our installation, we have Spring Cloud Config Server + Eureka Server, and then 2 modules that use this server component to bootstrap and discover services.

The problem that I am facing is that if I distribute two instances of the Eureka server and try to connect them (based on Two Peer Aware Eureka Servers in Documents ), they do not synchronize with each other. See Configs below and / or the code on GitHub .

Essentially, Peer1 starts up and looks great. Peer2 will start and look normal, with both peers showing each other in services. However, if the UserService module is twisted and registered with Peer1, Peer2 will never see it. If we then deploy the "Web" module pointing to Peer2, it will never be able to solve the UserService. They mainly act in isolation.

I tried several combinations of setting serviceUrl both on the server and on the Eureka server instance, but to no avail. Am I just setting something up wrong?

Peer 1 / default config:

 server: port: 8888 eureka: dashboard: path: /dashboard instance: hostname: peer1 leaseRenewalIntervalInSeconds: 3 client: serviceUrl: defaultZone: ${eureka.server.serviceUrl:http://localhost:${server.port}/eureka/} server: serviceUrl: defaultZone: http://localhost:${server.port}/eureka/ peer2: http://peer2/eureka/ waitTimeInMsWhenSyncEmpty: 0 spring: application: name: demo-config-service profiles: active: native # required for Spring Cloud Bus rabbitmq: host: ${DOCKER_IP:192.168.59.103} port: 5672 username: guest password: guest virtualHost: / cloud: config: server: prefix: /configs native: searchLocations: /Users/dave/workspace/oss/distributed-spring/modules/config-server/src/main/resources/testConfigs # git : # uri: https://github.com/joshlong/microservices-lab-configuration 

Peer-to-peer network configuration:

 server: port: 8889 eureka: dashboard: path: /dashboard instance: hostname: peer2 leaseRenewalIntervalInSeconds: 3 client: serviceUrl: defaultZone: ${eureka.server.serviceUrl:http://localhost:${server.port}/eureka/} server: serviceUrl: defaultZone: http://localhost:8888/eureka/ peer1: http://peer1/eureka/ waitTimeInMsWhenSyncEmpty: 0 spring: application: name: demo-config-service profiles: active: native # required for Spring Cloud Bus rabbitmq: host: ${DOCKER_IP:192.168.59.103} port: 5672 username: guest password: guest virtualHost: / cloud: config: server: prefix: /configs native: searchLocations: /Users/dave/workspace/oss/distributed-spring/modules/config-server/src/main/resources/testConfigs # git : # uri: https://github.com/joshlong/microservices-lab-configuration 
+5
source share
2 answers

There were a few problems. defaultZone should be in the client section as indicated in the docs. The defaultZone must have a port.

/ etc / hosts

 127.0.0.1 peer1 127.0.0.1 peer2 

Peer Configuration (Partial)

 eureka: instance: hostname: peer1 leaseRenewalIntervalInSeconds: 3 client: serviceUrl: defaultZone: http://peer2:8889/eureka/ 

Peer Configuration (Partial)

 eureka: dashboard: path: /dashboard instance: hostname: peer2 leaseRenewalIntervalInSeconds: 3 client: serviceUrl: defaultZone: http://peer1:8888/eureka/ server: waitTimeInMsWhenSyncEmpty: 0 

User Service Configuration (Partial) Invalid configuration port.

 spring: application: name: user-service cloud: config: uri: http://localhost:8888/configs 

You can see how the user service replicates to both peer1 and peer2. I can publish a PR for your code if you want.

Peer 1

Peer1

Peer 2

Peer2

+7
source

@spencergibb did not mention why this hack-ish workaround is not required. On the same host there is gotcha with the launch of more than one Eureka server. Netflix code ( com.netflix.eureka.cluster.PeerEurekaNodes.isThisMyUrl ) filters peer URL-addresses that are on the same host. Perhaps this was done to prevent the server from registering as its own partner (Im guessing here), but since they do not check the port, peer awareness does not work if the Eureka names in eureka.client.serviceUrl.defaultZone do not match. A hacky workaround for this is to identify unique hostnames and then map them to 127.0.0.1 in the /etc/hosts (or its Windows equivalent).

I created a blog post with Eureka details here that fills in some of the missing details from the Spring doc or Netflix blog. This is the result of several days of debugging and digging the source code.

+2
source

All Articles