Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service instances register to both eureka services that are peers

Tags:

spring-cloud

We are running in a peer to peer Eureka configuration. See below for the configuration.

  1. So when the services are started, they register to 10.202.10.95 (the primary) and we see them there with none showing on 10.202.10.97 (the secondary)
  2. If we kill 10.202.10.95 (the primary) then we see them show up on 10.202.10.97 (the secondary eureka).
  3. If we restart 10.202.10.95 (which was the primary), we see the services show up on 10.202.10.95 and also on 10.202.10.97. So services are visible on both eureka servers
  4. If we restart 10.202.10.97 (the secondary), the services vanish and are just visible on the primary (10.202.10.95)

Case 3 is unexpected to me. Is this a case of improper peer to peer Eureka configuration?

The eureka configuration is as follows: (we point these 2 instances to each other in a peer to peer configuration)

spring:
  profiles: api06-prod-int-discoveryserver # 10.202.10.95 eureka host
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://10.202.10.97:8761/eureka/

---
spring:
  profiles: api05-prod-int-discoveryserver # 10.202.10.97 eureka host
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://10.202.10.95:8761/eureka/

Each service has its configuration to eureka set like this: (we point to both instances with x.x.x.95 being the primary)

eureka:
  # these are settings for the client that gets services
  client:
    # enable these two settings if you want discovery to work
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://10.202.10.95:8761/eureka/,http://10.202.10.97:8761/eureka/
like image 589
EvilJinious1 Avatar asked Nov 10 '22 13:11

EvilJinious1


1 Answers

So, following some other posts and Spencer's response I checked and my configuration was incorrect. After I changed it, it responds correctly.

This is the Eureka settings. I run 2 eureka servers, one with profile peer1 and the other with profile peer2.

---
spring:
  profiles: peer1 # not standalone

server:
  port: 8761

eureka:
  instance:
    hostname: peer2
    leaseRenewalIntervalInSeconds: 3
  client:
    serviceUrl:
      defaultZone: http://localhost:8762/eureka/

---
spring:
  profiles: peer2 # not standalone

server:
  port: 8762

eureka:
  instance:
    hostname: peer1
    leaseRenewalIntervalInSeconds: 3
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  server:
    waitTimeInMsWhenSyncEmpty: 0

The Service that I have connecting is configured like this

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
  instance:
    statusPageUrlPath: /${info.app.name}/manage/info
    homePageUrlPath: /${info.app.name}/manage
    healthCheckUrlPath: /${info.app.name}/manage/health
    preferIpAddress: true

After I run my service, I can see it connect to both discovery services and if I kill either then it is visible on the other discovery service.

like image 55
EvilJinious1 Avatar answered Jan 04 '23 03:01

EvilJinious1