Search code examples
spring-cloudnetflix-eurekaspring-cloud-netflix

Can Eureka Clients discover the Server without an explicit URL?


In a sample Spring Boot project I've setup, I point my Eureka clients to my Eureka server with a URL like so: eureka.serviceUrl.default=http://localhost:8761/eureka/v2/

I'm worried about what happens if the Eureka Server dies.

As a remedy, is there a way to setup multiple instance of Eureka Server and configure the Eureka Clients to discover them (w/o relying on an absolute URL)?


Solution

  • Eureka framework support multiple Eureka Server instance. The client choose a server while initialization and propose request to the server until the server dies.

    For example, if you start two eureka Servers locally on port 8761 and 8762 with same configuration :

    eureka.serviceUrl.default=http://localhost:8761/eureka/v2/,http://localhost:8762/eureka/v2/
    

    And your client app should also got the same configuration of eureka.serviceUrl.default; When the app start up, it will choose localhost:8761 as eureka server and send register request to localhost:8761, then localhost:8761 will record and send a same register request to localhost:8762; when localhost:8761 dies, the client app will switch to localhost:8762 to send heartbeat requests.